Compare commits

..

No commits in common. "b6be3bdefc28c2783fb01c2dcf8464d77b428758" and "c2b34a3bb757ab4f36125eff112fe78991f99f78" have entirely different histories.

3 changed files with 87 additions and 130 deletions

View File

@ -21,20 +21,19 @@
env_default = emonth2 env_default = emonth2
[common] [common]
monitor_speed = 115200
build_flags = -D BUILD_TAG=3.2.0
# http://docs.platformio.org/en/stable/projectconf.html#lib-deps # http://docs.platformio.org/en/stable/projectconf.html#lib-deps
lib_deps_external = lib_deps_external =
DallasTemperature @3.7.7 DallasTemperature @3.7.7
https://github.com/jcw/jeelib.git#f097c0039c926881d80a74bec7a7aa020de610ee JeeLib @c057b5f4c0
https://github.com/LowPowerLab/SI7021.git Si7021 @c5ce0922ef
monitor_speed = 115200
build_flags = -D BUILD_TAG=3.2.0
[env:emonth2] [env:emonth2]
platform = atmelavr platform = atmelavr
framework = arduino framework = arduino
board = uno board = uno
build_flags = ${common.build_flags}
lib_deps = ${common.lib_deps_external} lib_deps = ${common.lib_deps_external}
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
@ -55,4 +54,3 @@ framework = arduino
board = uno board = uno
lib_deps = ${common.lib_deps_external} lib_deps = ${common.lib_deps_external}
build_flags = !echo '-DBUILD_TAG='$TRAVIS_TAG build_flags = !echo '-DBUILD_TAG='$TRAVIS_TAG
monitor_speed = ${common.monitor_speed}

View File

@ -1,7 +1,4 @@
/*
* Configuration file for EmonTH_V2.ino V3.2.6
*
*/
#include <EEPROM.h> #include <EEPROM.h>
@ -49,18 +46,15 @@ static void config (char c) {
nodeID = value; nodeID = value;
break; break;
case 'b': // set band: 4 = 433, 8 = 868, 9 = 915 case 'b': // set band: 4 = 433, 8 = 868, 9 = 915
value = bandToFreq(value); value = bandToFreq(value);
if (value){ if (value)
RF_freq = value; RF_freq = value;
}
break; break;
case 'g': // set network group case 'g': // set network group
if (value>=0){ if (value>=0)
networkGroup = value; networkGroup = value;
}
break; break;
case 's': // Save to EEPROM. Atemga328p has 1kb EEPROM case 's': // Save to EEPROM. Atemga328p has 1kb EEPROM

View File

@ -30,15 +30,12 @@
31 - Special allocation in JeeLib RFM12 driver - Node31 can communicate with nodes on any network group 31 - Special allocation in JeeLib RFM12 driver - Node31 can communicate with nodes on any network group
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
Change log: Change log:
V3.2.6 - [30/9/21 - RW] Multiple external DS18B20 sensors accepted. No change to config file.
V3.2.5 - [30/1/21 - RW] Factory test transmission moved to Grp 1 to avoid interference with recorded data at power-up.
Missing declaration of showString( ) added.
V3.2.4 - (25/05/18) Add prompt for serial config V3.2.4 - (25/05/18) Add prompt for serial config
V3.2.3 - (17/07/17) Fix DIP switch had no effect V3.2.3 - (17/07/17) Fix DIP switch had no effect
V3.2.2 - (12/05/17) Fix DIP switch nodeID not being read when EEPROM is configures V3.2.2 - (12/05/17) Fix DIP switch nodeID not being read when EEPROM is configures
V3.2.1 - (30/11/16) Fix emonTx port typo V3.2.1 - (30/11/16) Fix emonTx port typo
V3.2.0 - (13/11/16) Run-time serial nodeID config V3.2.0 - (13/11/16) Run-time serial nodeID config
V3.1.0 - (19/10/16) Test for RFM69CW and SI7021 at startup, allow serial use without RF present V3.1.0 - (19/10/16) Test for RFM69CW and SI7021 at startup, allow serial use without RF prescent
V3.0.0 - (xx/10/16) Add support for SI7021 sensor instead of DHT22 (emonTH V2.0 hardware) V3.0.0 - (xx/10/16) Add support for SI7021 sensor instead of DHT22 (emonTH V2.0 hardware)
^^^ emonTH V2.0 hardware ^^^ ^^^ emonTH V2.0 hardware ^^^
V2.7 - (15/09/16) Serial print serial pairs for emonesp compatiable e.g. temp:210,humidity:56 V2.7 - (15/09/16) Serial print serial pairs for emonesp compatiable e.g. temp:210,humidity:56
@ -53,9 +50,6 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
emonhub.conf node decoder: emonhub.conf node decoder:
See: https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md See: https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md
NOTE: If the number of external temperature sensors is changed from 1, the 4 lines below: 'names = ...',
'datacodes = ...', 'scales = ...' & 'units = ...' must be changed to suit.
The maximum recommended is 4.
[[23]] [[23]]
nodename = emonTH_5 nodename = emonTH_5
@ -68,12 +62,12 @@
units = C,C,%,V,p units = C,C,%,V,p
*/ */
// ------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------
#define NUM_EXTERNAL_TEMP_SENSORS 1 // Specify number of external temperature sensors that are connected. #define EXTERNAL_TEMP_SENSORS 1 // Specify number of external temperature sensors that are connected
boolean debug=1; // Set to 1 to few debug serial output boolean debug=1; // Set to 1 to few debug serial output
boolean flash_led=0; // Flash LED after each sample (battery drain) default=0 boolean flash_led=0; // Flash LED after each sample (battery drain) default=0
const unsigned int version = 326 ; // firmware version const unsigned int version = 324; // firmware version
// These variables control the transmit timing of the emonTH // These variables control the transmit timing of the emonTH
const unsigned long WDT_PERIOD = 80; // mseconds. const unsigned long WDT_PERIOD = 80; // mseconds.
const unsigned long WDT_MAX_NUMBER = 690; // Data sent after WDT_MAX_NUMBER periods of WDT_PERIOD ms without pulses: const unsigned long WDT_MAX_NUMBER = 690; // Data sent after WDT_MAX_NUMBER periods of WDT_PERIOD ms without pulses:
@ -83,7 +77,6 @@ const unsigned long PULSE_MAX_DURATION = 50;
#define RF69_COMPAT 1 // Set to 1 if using RFM69CW or 0 is using RFM12B #define RF69_COMPAT 1 // Set to 1 if using RFM69CW or 0 is using RFM12B
#define FACTORYTESTGROUP 1 // R.F. Group for factory test only
#include <JeeLib.h> // https://github.com/jcw/jeelib #include <JeeLib.h> // https://github.com/jcw/jeelib
#include <RF69_avr.h> #include <RF69_avr.h>
#define REG_SYNCVALUE1 0x2F #define REG_SYNCVALUE1 0x2F
@ -131,7 +124,7 @@ boolean DS18B20; // create
// https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md // https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md
typedef struct { // RFM RF payload datastructure typedef struct { // RFM RF payload datastructure
int temp; int temp;
int temp_external[NUM_EXTERNAL_TEMP_SENSORS]; int temp_external[EXTERNAL_TEMP_SENSORS];
int humidity; int humidity;
int battery; int battery;
unsigned long pulsecount; unsigned long pulsecount;
@ -139,8 +132,8 @@ typedef struct { // RFM RF
Payload emonth; Payload emonth;
int numSensors; int numSensors;
//addresses of sensors //addresses of sensors, MAX 4!!
byte allAddress [NUM_EXTERNAL_TEMP_SENSORS][8]; // 8 bytes per address byte allAddress [4][8]; // 8 bytes per address
volatile unsigned long pulseCount; volatile unsigned long pulseCount;
unsigned long WDT_number; unsigned long WDT_number;
@ -158,15 +151,11 @@ const char helpText1[] PROGMEM = // Availa
" s - save config to EEPROM\n" " s - save config to EEPROM\n"
" v - Show firmware version\n" " v - Show firmware version\n"
; ;
static void showString(PGM_P s);
//################################################################################################################################ //################################################################################################################################
//################################################################################################################################ //################################################################################################################################
#ifndef UNIT_TEST // IMPORTANT LINE! // http://docs.platformio.org/en/stable/plus/unit-testing.html #ifndef UNIT_TEST // IMPORTANT LINE! // http://docs.platformio.org/en/stable/plus/unit-testing.html
void setup() void setup() {
{
//################################################################################################################################ //################################################################################################################################
pinMode(LED,OUTPUT); digitalWrite(LED,HIGH); // Status LED on pinMode(LED,OUTPUT); digitalWrite(LED,HIGH); // Status LED on
@ -211,8 +200,7 @@ void setup()
// } // }
RF_STATUS=1; RF_STATUS=1;
if (RF_STATUS==1) if (RF_STATUS==1){
{
load_config(); // Load RF config from EEPROM (if any exist) load_config(); // Load RF config from EEPROM (if any exist)
// Add effect of DIP switch positions to nodeID // Add effect of DIP switch positions to nodeID
@ -222,7 +210,19 @@ void setup()
if ((DIP1 == LOW) && (DIP2 == LOW)) nodeID=nodeID+3; if ((DIP1 == LOW) && (DIP2 == LOW)) nodeID=nodeID+3;
if (debug) Serial.println("Int RFM..."); if (debug) Serial.println("Int RFM...");
rf12_initialize(nodeID, RF_freq, FACTORYTESTGROUP); // Initialize RFM with Factory Test rf12_initialize(nodeID, RF_freq, networkGroup); // Initialize RFM
if (debug){
Serial.println("RFM Started");
Serial.print("Node: ");
Serial.print(nodeID);
Serial.print(" Freq: ");
if (RF_freq == RF12_433MHZ) Serial.print("433Mhz");
if (RF_freq == RF12_868MHZ) Serial.print("868Mhz");
if (RF_freq == RF12_915MHZ) Serial.print("915Mhz");
Serial.print(" Network: ");
Serial.println(networkGroup);
}
// Send RFM69CW test sequence (for factory testing) // Send RFM69CW test sequence (for factory testing)
for (int i=10; i>-1; i--) for (int i=10; i>-1; i--)
{ {
@ -233,20 +233,6 @@ void setup()
rf12_sendWait(2); rf12_sendWait(2);
emonth.temp=0; emonth.temp=0;
// end of factory test sequence // end of factory test sequence
if (debug)
{
Serial.println("RFM Started");
Serial.print("Node: ");
Serial.print(nodeID);
Serial.print(" Freq: ");
if (RF_freq == RF12_433MHZ) Serial.print("433MHz");
if (RF_freq == RF12_868MHZ) Serial.print("868MHz");
if (RF_freq == RF12_915MHZ) Serial.print("915MHz");
Serial.print(" Network: ");
Serial.println(networkGroup);
}
rf12_initialize(nodeID, RF_freq, networkGroup); // Re-Initialize RFM with 'normal' Group
rf12_sleep(RF12_SLEEP); rf12_sleep(RF12_SLEEP);
} }
@ -264,8 +250,7 @@ void setup()
{ {
SI7021_sensor.begin(); SI7021_sensor.begin();
int deviceid = SI7021_sensor.getDeviceId(); int deviceid = SI7021_sensor.getDeviceId();
if (deviceid!=0) if (deviceid!=0) {
{
SI7021_status=1; SI7021_status=1;
if (debug){ if (debug){
si7021_env data = SI7021_sensor.getHumidityAndTemperature(); si7021_env data = SI7021_sensor.getHumidityAndTemperature();
@ -275,14 +260,12 @@ void setup()
Serial.print("SI7021 h: "); Serial.println(data.humidityBasisPoints/100.0); Serial.print("SI7021 h: "); Serial.println(data.humidityBasisPoints/100.0);
} }
} }
else else {
{
SI7021_status=0; SI7021_status=0;
if (debug) Serial.println("SI7021 Error"); if (debug) Serial.println("SI7021 Error");
} }
} }
else else {
{
SI7021_status=0; SI7021_status=0;
if (debug) Serial.println("SI7021 Error"); if (debug) Serial.println("SI7021 Error");
} }
@ -306,8 +289,7 @@ void setup()
else else
{ {
DS18B20=1; DS18B20=1;
if (debug==1) if (debug==1) {
{
Serial.print(numSensors); Serial.println(" DS18B20"); Serial.print(numSensors); Serial.println(" DS18B20");
} }
} }
@ -326,28 +308,22 @@ void setup()
//################################################################################################################################ //################################################################################################################################
// RF Config mode // RF Config mode
//################################################################################################################################ //################################################################################################################################
if (RF_STATUS==1) if (RF_STATUS==1){
{
Serial.println(""); Serial.println("");
Serial.println("'+++' then [Enter] for RF config mode"); Serial.println("'+++' then [Enter] for RF config mode");
Serial.println("(Arduino IDE Serial Monitor: make sure 'Both NL & CR' is selected)"); Serial.println("(Arduino IDE Serial Monitor: make sure 'Both NL & CR' is selected)");
Serial.println("waiting 5s..."); Serial.println("waiting 5s...");
start = millis(); start = millis();
while (millis() < (start + 5000)) while (millis() < (start + 5000)){
{
// If serial input of keyword string '+++' is entered during 5s power-up then enter config mode // If serial input of keyword string '+++' is entered during 5s power-up then enter config mode
if (Serial.available()) if (Serial.available()){
{ if ( Serial.readString() == "+++\r\n"){
if ( Serial.readString() == "+++\r\n")
{
Serial.println("Entering config mode..."); Serial.println("Entering config mode...");
showString(helpText1); showString(helpText1);
// char c[]="v" // char c[]="v"
config(char('v')); config(char('v'));
while(1) while(1){
{ if (Serial.available()){
if (Serial.available())
{
config(Serial.read()); config(Serial.read());
} }
} }
@ -367,8 +343,7 @@ void setup()
// power_timer0_disable(); //don't disable necessary for the DS18B20 library // power_timer0_disable(); //don't disable necessary for the DS18B20 library
// Only turn off LED if both sensor and RF69CW are working // Only turn off LED if both sensor and RF69CW are working
if ((RF_STATUS) && (SI7021_status)) if ((RF_STATUS) && (SI7021_status)){
{
digitalWrite(LED,LOW); // turn off LED to indciate end setup digitalWrite(LED,LOW); // turn off LED to indciate end setup
} }
} // end of setup } // end of setup
@ -380,8 +355,7 @@ void loop()
//################################################################################################################################ //################################################################################################################################
{ {
if (p) if (p) {
{
Sleepy::loseSomeTime(PULSE_MAX_DURATION); Sleepy::loseSomeTime(PULSE_MAX_DURATION);
p=0; p=0;
} }
@ -405,11 +379,9 @@ void loop()
sensors.requestTemperatures(); // Send the command to get temperatures sensors.requestTemperatures(); // Send the command to get temperatures
dodelay(ASYNC_DELAY); //Must wait for conversion, since we use ASYNC mode dodelay(ASYNC_DELAY); //Must wait for conversion, since we use ASYNC mode
for(int j=0; j<NUM_EXTERNAL_TEMP_SENSORS;j++) for(int j=0;j<EXTERNAL_TEMP_SENSORS;j++) {
{
float temp=(sensors.getTempC(allAddress[j])); float temp=(sensors.getTempC(allAddress[j]));
if ((temp<125.0) && (temp>-40.0)) if ((temp<125.0) && (temp>-40.0)) {
{
emonth.temp_external[j]=(temp*10); emonth.temp_external[j]=(temp*10);
} }
} }
@ -430,8 +402,7 @@ void loop()
// Read SI7021 // Read SI7021
// Read from SI7021 SPI temp & humidity sensor // Read from SI7021 SPI temp & humidity sensor
if (SI7021_status==1) if (SI7021_status==1){
{
power_twi_enable(); power_twi_enable();
si7021_env data = SI7021_sensor.getHumidityAndTemperature(); si7021_env data = SI7021_sensor.getHumidityAndTemperature();
emonth.temp = (data.celsiusHundredths*0.1); emonth.temp = (data.celsiusHundredths*0.1);
@ -441,8 +412,7 @@ void loop()
// Send data via RF // Send data via RF
if (RF_STATUS) if (RF_STATUS){
{
power_spi_enable(); power_spi_enable();
rf12_sleep(RF12_WAKEUP); rf12_sleep(RF12_WAKEUP);
dodelay(30); // wait for module to wakup dodelay(30); // wait for module to wakup
@ -455,8 +425,7 @@ void loop()
power_spi_disable(); power_spi_disable();
} }
if (flash_led) if (flash_led){
{
digitalWrite(LED,HIGH); digitalWrite(LED,HIGH);
dodelay(100); dodelay(100);
digitalWrite(LED,LOW); digitalWrite(LED,LOW);
@ -469,21 +438,17 @@ void loop()
{ {
Serial.print("temp:");Serial.print(emonth.temp); Serial.print(","); Serial.print("temp:");Serial.print(emonth.temp); Serial.print(",");
if (DS18B20) if (DS18B20){
{ for(int j=0;j<EXTERNAL_TEMP_SENSORS;j++) {
for(int j=0;j<NUM_EXTERNAL_TEMP_SENSORS;j++)
{
Serial.print("tempex");Serial.print(j);Serial.print(":");Serial.print(emonth.temp_external[j]); Serial.print(","); Serial.print("tempex");Serial.print(j);Serial.print(":");Serial.print(emonth.temp_external[j]); Serial.print(",");
} }
} }
if (SI7021_status) if (SI7021_status){
{
Serial.print("humidity:");Serial.print(emonth.humidity); Serial.print(","); Serial.print("humidity:");Serial.print(emonth.humidity); Serial.print(",");
} }
Serial.print("batt:"); Serial.print(emonth.battery); Serial.print("batt:"); Serial.print(emonth.battery);
if (emonth.pulsecount > 0) if (emonth.pulsecount > 0) {
{
Serial.print(","); Serial.print(",");
Serial.print("pulse:"); Serial.print(emonth.pulsecount); Serial.print("pulse:"); Serial.print(emonth.pulsecount);
} }