Added platformio to build_script
Have only tested that the build_script works to build. Have not verify the build_script on hardware!
This commit is contained in:
parent
1da7e027e4
commit
d2c128035d
|
|
@ -0,0 +1,9 @@
|
||||||
|
[submodule "libraries/arduino_github"]
|
||||||
|
path = libraries/arduino_github
|
||||||
|
url = git@github.com:RobTillaart/Arduino.git
|
||||||
|
[submodule "libraries/mysensors_github"]
|
||||||
|
path = libraries/mysensors_github
|
||||||
|
url = git@github.com:mysensors/Arduino.git
|
||||||
|
[submodule "libraries/milvert_mysensors"]
|
||||||
|
path = libraries/milvert_mysensors
|
||||||
|
url = git@github.com:milvert/Arduino.git
|
||||||
10
README.md
10
README.md
|
|
@ -1 +1,9 @@
|
||||||
# mysensors_nodes
|
# My personal [MySensors](http://mysensors.org) nodes
|
||||||
|
|
||||||
|
To upload a sketch to a node run build_project.sh.
|
||||||
|
|
||||||
|
## ToDo:
|
||||||
|
- Each node should have a KiCad-schematic
|
||||||
|
- Add external dependencies
|
||||||
|
- Fix includes in temp_hum_sensor
|
||||||
|
- Better comments
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
PARENT_DIR="$(pwd)"
|
||||||
|
|
||||||
|
#Add a path to all libraries
|
||||||
|
MYSENSORS_LIB="libraries/mysensors_github/libraries/MySensors"
|
||||||
|
DHT_LIB="libraries/mysensors_github/libraries/DHT"
|
||||||
|
#DHT_LIB="libraries/arduino_github/libraries/DHTlib"
|
||||||
|
|
||||||
|
function CHECK_DEPENDENCIES {
|
||||||
|
|
||||||
|
if ! which platformio >/dev/null; then
|
||||||
|
echo "Install platfromio!"
|
||||||
|
echo "http://platformio.org/#!/get-started"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$DISPLAY" ]; then
|
||||||
|
if which arduino > /dev/null; then
|
||||||
|
ARDUINO=$(which arduino)
|
||||||
|
else
|
||||||
|
echo "Install arduino"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if which arduino-headless > /dev/null; then
|
||||||
|
ARDUINO=$(which arduino-headless)
|
||||||
|
else
|
||||||
|
echo "Install arduino-headless"
|
||||||
|
echo "Create arduino-headless and copy:"
|
||||||
|
echo "
|
||||||
|
#!/bin/bash
|
||||||
|
Xvfb :1 -nolisten tcp -screen :1 1280x800x24 &
|
||||||
|
xvfb=\"$!\"
|
||||||
|
DISPLAY=:1 arduino \$@
|
||||||
|
kill -9 \$xvfb
|
||||||
|
"
|
||||||
|
echo "and make arduino-headless runnable (/usr/local/bin/arduino-headless)"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# List all nodes/gateways that are possible to build
|
||||||
|
###
|
||||||
|
function LIST_DIR {
|
||||||
|
|
||||||
|
local i=0
|
||||||
|
dirs=( $(find . -maxdepth 1 -type d -printf '%P\n') )
|
||||||
|
for dir in "${dirs[@]}"; do
|
||||||
|
if [ "${dir}" == ".git" ]; then
|
||||||
|
unset dirs[$i]
|
||||||
|
elif [ "${dir}" == "libraries" ]; then
|
||||||
|
unset dirs[$i]
|
||||||
|
fi
|
||||||
|
i=$i+1
|
||||||
|
done
|
||||||
|
dirs=("${dirs[@]}" "Quit")
|
||||||
|
echo "Which project do you want to build? "
|
||||||
|
select dir in "${dirs[@]}"; do
|
||||||
|
if [ "${dir}" == "Quit" ]; then
|
||||||
|
echo "Quit"
|
||||||
|
break
|
||||||
|
elif [[ $REPLY -gt 0 && $REPLY < ${#dirs[@]} ]] ; then
|
||||||
|
echo "${dir} selected"
|
||||||
|
BUILD_WITH_PLATFORMIO "${dir}"
|
||||||
|
#BUILD_WITH_ARDUINO "${dir}"
|
||||||
|
LIST_DIR
|
||||||
|
else
|
||||||
|
echo "Select between 0 and ${#dirs[@]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# Use the the arduino cli for building.
|
||||||
|
# TODO: Add interface for build with differnet boards and 8Mhz/16Mhz
|
||||||
|
###
|
||||||
|
BUILD_WITH_ARDUINO() {
|
||||||
|
LINK_HEADER "${dir}" "arduino"
|
||||||
|
${ARDUINO} --upload -v --board arduino:avr:pro --pref build.f_cpu=8000000 --pref build.mcu=atmega328p --pref compiler.warning_level=all --pref sketchbook.path="${PWD}/${dir}" "${PWD}/${dir}/${dir}.ino"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# TODO: Platformio dosen't work with MySensors lib.
|
||||||
|
###
|
||||||
|
BUILD_WITH_PLATFORMIO() {
|
||||||
|
LINK_HEADER "${dir}" "platformio"
|
||||||
|
(cd "${1}" && platformio run --target clean)
|
||||||
|
(cd "${1}" && platformio run)
|
||||||
|
|
||||||
|
if [ "$?" -ne "0" ]; then
|
||||||
|
echo "Compiliing failed "
|
||||||
|
echo "Exiting"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -r -p "Want to upload? [Y/n]" response
|
||||||
|
response=${response,,} # tolower
|
||||||
|
if [ "${response}" = "" ]; then
|
||||||
|
response='yes'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $response =~ ^(yes|y| ) ]]; then
|
||||||
|
echo "Upload"
|
||||||
|
(cd "${1}" && platformio run --target upload)
|
||||||
|
else
|
||||||
|
echo "Not upload"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# Checks which includes the sketch wants and creates a symlink to
|
||||||
|
# the lib
|
||||||
|
# TODO: Platformio dosen't work with MySensors lib.
|
||||||
|
###
|
||||||
|
LINK_HEADER() {
|
||||||
|
cd "${1}"
|
||||||
|
echo "Link_header "
|
||||||
|
|
||||||
|
# Scan the ino file for #include <lib.h>
|
||||||
|
if [ "${2}" = "arduino" ]; then
|
||||||
|
local header_files=($(grep "include" ./*.ino | sed 's/\(#include <\)\(.*\)\(.h>\)/\2/'))
|
||||||
|
lib_dir=libraries
|
||||||
|
else
|
||||||
|
echo "platformio"
|
||||||
|
local header_files=($(grep "include" src/*.ino | sed 's/\(#include <\)\(.*\)\(.h>\)/\2/'))
|
||||||
|
lib_dir=lib
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$lib_dir" ]; then
|
||||||
|
mkdir "$lib_dir"
|
||||||
|
else
|
||||||
|
rm -r ${lib_dir}/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in "${header_files[@]}"; do
|
||||||
|
case $file in
|
||||||
|
"MySensor")
|
||||||
|
# Fix path to mysensors lib in platformio.ini
|
||||||
|
if [ "${2}" = "platformio" ]; then
|
||||||
|
sed -i "s:\(build_flags\s*=\)\(.*\):\1 \-I$PARENT_DIR/$MYSENSORS_LIB:" platformio.ini
|
||||||
|
cat platformio.ini
|
||||||
|
elif [[ ! -d "$lib_dir/${file}" ]]; then
|
||||||
|
ln -s "${PARENT_DIR}/${MYSENSORS_LIB}" "$lib_dir/${file}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"DHT")
|
||||||
|
if [[ ! -d "$lib_dir/${file}" ]]; then
|
||||||
|
ln -s "${PARENT_DIR}/${DHT_LIB}" "$lib_dir/${file}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Nothing ${file}"
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
cd "${PARENT_DIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_DEPENDENCIES
|
||||||
|
LIST_DIR
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 34ff8cfd021fd214d3850a1c37f739c84e3c7815
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 59f887687058e5abdfbf80354cb5bf246e45cca7
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 367dee18b033f02199576b65b0eb5a28c20e6abd
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
[env:pro8MHzatmega328]
|
||||||
|
platform = atmelavr
|
||||||
|
framework = arduino
|
||||||
|
board = pro8MHzatmega328
|
||||||
|
build_flags = -I/home/simon/repo/milvert_sensor/libraries/mysensors_github/libraries/MySensors
|
||||||
|
lib_ignore = MySensors
|
||||||
|
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
/**
|
||||||
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||||
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
|
* network topology allowing messages to be routed to nodes.
|
||||||
|
*
|
||||||
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
|
* Copyright (C) 2013-2015 Sensnology AB
|
||||||
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
|
*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
*******************************
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* The ArduinoGateway prints data received from sensors on the serial link.
|
||||||
|
* The gateway accepts input on seral which will be sent out on radio network.
|
||||||
|
*
|
||||||
|
* The GW code is designed for Arduino Nano 328p / 16MHz
|
||||||
|
*
|
||||||
|
* Wire connections (OPTIONAL):
|
||||||
|
* - Inclusion button should be connected between digital pin 3 and GND
|
||||||
|
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
||||||
|
*
|
||||||
|
* LEDs (OPTIONAL):
|
||||||
|
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
|
||||||
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Enable debug prints to serial monitor
|
||||||
|
#define MY_DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
// Enable and select radio type attached
|
||||||
|
#define MY_RADIO_NRF24
|
||||||
|
//#define MY_RADIO_RFM69
|
||||||
|
|
||||||
|
// Set LOW transmit power level as default, if you have an amplified NRF-module and
|
||||||
|
// power your radio separately with a good regulator you can turn up PA level.
|
||||||
|
#define MY_RF24_PA_LEVEL RF24_PA_LOW
|
||||||
|
|
||||||
|
// Enable serial gateway
|
||||||
|
#define MY_GATEWAY_SERIAL
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
|
#define MY_LEDS_BLINKING_FEATURE
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Inverses the behavior of leds
|
||||||
|
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||||
|
|
||||||
|
// Enable inclusion mode
|
||||||
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
|
// Enable Inclusion mode button on gateway
|
||||||
|
#define MY_INCLUSION_BUTTON_FEATURE
|
||||||
|
|
||||||
|
// Inverses behavior of inclusion button (if using external pullup)
|
||||||
|
//#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
|
||||||
|
|
||||||
|
// Set inclusion mode duration (in seconds)
|
||||||
|
#define MY_INCLUSION_MODE_DURATION 60
|
||||||
|
// Digital pin used for inclusion mode button
|
||||||
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
||||||
|
#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
|
||||||
|
#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <MySensor.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Setup locally attached sensors
|
||||||
|
}
|
||||||
|
|
||||||
|
void presentation() {
|
||||||
|
// Present locally attached sensors
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Send locally attached sensor data here
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
[env:pro8MHzatmega328]
|
||||||
|
platform = atmelavr
|
||||||
|
framework = arduino
|
||||||
|
board = pro8MHzatmega328
|
||||||
|
build_flags = -I/home/simon/repo/milvert_sensor/libraries/mysensors_github/libraries/MySensors
|
||||||
|
lib_ignore = MySensors
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
/**
|
||||||
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||||
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
|
* network topology allowing messages to be routed to nodes.
|
||||||
|
*
|
||||||
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
|
* Copyright (C) 2013-2015 Sensnology AB
|
||||||
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
|
*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
*******************************
|
||||||
|
*
|
||||||
|
* REVISION HISTORY
|
||||||
|
* Version 1.0 - Henrik EKblad
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* This sketch provides an example how to implement a humidity/temperature
|
||||||
|
* sensor using DHT11/DHT-22
|
||||||
|
* http://www.mysensors.org/build/humidity
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Enable debug prints
|
||||||
|
#define MY_DEBUG
|
||||||
|
|
||||||
|
// Enable and select radio type attached
|
||||||
|
#define MY_RADIO_NRF24
|
||||||
|
//#define MY_RADIO_RFM69
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <MySensor.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
|
||||||
|
#define CHILD_ID_HUM 0
|
||||||
|
#define CHILD_ID_TEMP 1
|
||||||
|
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
|
||||||
|
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||||
|
|
||||||
|
DHT dht;
|
||||||
|
float lastTemp;
|
||||||
|
float lastHum;
|
||||||
|
boolean metric = true;
|
||||||
|
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
||||||
|
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
|
||||||
|
|
||||||
|
metric = getConfig().isMetric;
|
||||||
|
}
|
||||||
|
|
||||||
|
void presentation()
|
||||||
|
{
|
||||||
|
// Send the Sketch Version Information to the Gateway
|
||||||
|
sendSketchInfo("Humidity", "1.0");
|
||||||
|
|
||||||
|
// Register all sensors to gw (they will be created as child devices)
|
||||||
|
present(CHILD_ID_HUM, S_HUM);
|
||||||
|
present(CHILD_ID_TEMP, S_TEMP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
delay(dht.getMinimumSamplingPeriod());
|
||||||
|
|
||||||
|
float temperature = dht.getTemperature();
|
||||||
|
if (isnan(temperature)) {
|
||||||
|
Serial.println("Failed reading temperature from DHT");
|
||||||
|
} else if (temperature != lastTemp) {
|
||||||
|
lastTemp = temperature;
|
||||||
|
if (!metric) {
|
||||||
|
temperature = dht.toFahrenheit(temperature);
|
||||||
|
}
|
||||||
|
send(msgTemp.set(temperature, 1));
|
||||||
|
Serial.print("T: ");
|
||||||
|
Serial.println(temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
float humidity = dht.getHumidity();
|
||||||
|
if (isnan(humidity)) {
|
||||||
|
Serial.println("Failed reading humidity from DHT");
|
||||||
|
} else if (humidity != lastHum) {
|
||||||
|
lastHum = humidity;
|
||||||
|
send(msgHum.set(humidity, 1));
|
||||||
|
Serial.print("H: ");
|
||||||
|
Serial.println(humidity);
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(SLEEP_TIME); //sleep a bit
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue