Changed to send every 30 s.
This commit is contained in:
parent
b6be3bdefc
commit
3a4b4e6fc9
|
|
@ -0,0 +1,5 @@
|
|||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
# targets = upload
|
||||
|
||||
[platformio]
|
||||
env_default = emonth2
|
||||
default_envs = emonth2
|
||||
|
||||
[common]
|
||||
monitor_speed = 115200
|
||||
|
|
|
|||
|
|
@ -68,20 +68,19 @@
|
|||
units = C,C,%,V,p
|
||||
*/
|
||||
// -------------------------------------------------------------------------------------------------------------
|
||||
#define NUM_EXTERNAL_TEMP_SENSORS 1 // Specify number of external temperature sensors that are connected.
|
||||
#define NUM_EXTERNAL_TEMP_SENSORS 0 // Specify number of external temperature sensors that are connected.
|
||||
|
||||
boolean debug=1; // Set to 1 to few debug serial output
|
||||
boolean debug = 0; // Set to 1 to few debug serial output
|
||||
boolean flash_led = 0; // Flash LED after each sample (battery drain) default=0
|
||||
|
||||
const unsigned int version = 326; // firmware version
|
||||
// These variables control the transmit timing of the emonTH
|
||||
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:
|
||||
// 690x 80 = 55.2 seconds (it needs to be about 5s less than the record interval in emoncms)
|
||||
const unsigned long WDT_MAX_NUMBER = 315; // Data sent after WDT_MAX_NUMBER periods of WDT_PERIOD ms without pulses:
|
||||
// 315 * 80 = 25.2 seconds (it needs to be about 5s less than the record interval in emoncms)
|
||||
const unsigned long PULSE_MAX_NUMBER = 100; // Data sent after PULSE_MAX_NUMBER pulses
|
||||
const unsigned long PULSE_MAX_DURATION = 50;
|
||||
|
||||
|
||||
#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
|
||||
|
|
@ -89,7 +88,6 @@ const unsigned long PULSE_MAX_DURATION = 50;
|
|||
#define REG_SYNCVALUE1 0x2F
|
||||
boolean RF_STATUS;
|
||||
|
||||
|
||||
byte RF_freq = RF12_433MHZ; // Frequency of RF12B module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.
|
||||
byte nodeID = 23; // EmonTH temperature RFM12B node ID - should be unique on network
|
||||
int networkGroup = 210; // EmonTH RFM12B wireless network group - needs to be same as emonBase and emonGLCD
|
||||
|
|
@ -103,7 +101,10 @@ const int TEMPERATURE_PRECISION=11; // 9 (93.
|
|||
#include <avr/sleep.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption
|
||||
ISR(WDT_vect)
|
||||
{
|
||||
Sleepy::watchdogEvent();
|
||||
} // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption
|
||||
|
||||
// SI7021_status SPI temperature & humidity sensor
|
||||
#include <Wire.h>
|
||||
|
|
@ -129,7 +130,8 @@ boolean DS18B20; // create
|
|||
|
||||
// Note: Please update emonhub configuration guide on OEM wide packet structure change:
|
||||
// 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_external[NUM_EXTERNAL_TEMP_SENSORS];
|
||||
int humidity;
|
||||
|
|
@ -156,8 +158,7 @@ const char helpText1[] PROGMEM = // Availa
|
|||
" <n> b - set MHz band (4 = 433, 8 = 868, 9 = 915)\n"
|
||||
" <nnn> g - set network group (RFM12 only allows 212, 0 = any)\n"
|
||||
" s - save config to EEPROM\n"
|
||||
" v - Show firmware version\n"
|
||||
;
|
||||
" v - Show firmware version\n";
|
||||
|
||||
static void showString(PGM_P s);
|
||||
|
||||
|
|
@ -169,7 +170,8 @@ void setup()
|
|||
{
|
||||
//################################################################################################################################
|
||||
|
||||
pinMode(LED,OUTPUT); digitalWrite(LED,HIGH); // Status LED on
|
||||
pinMode(LED, OUTPUT);
|
||||
digitalWrite(LED, HIGH); // Status LED on
|
||||
|
||||
// Unused pins configure as input pull up for low power
|
||||
// http://electronics.stackexchange.com/questions/43460/how-should-unused-i-o-pins-be-configured-on-atmega328p-for-lowest-power-consumpt
|
||||
|
|
@ -187,12 +189,12 @@ void setup()
|
|||
boolean DIP1 = digitalRead(DIP_switch1);
|
||||
boolean DIP2 = digitalRead(DIP_switch2);
|
||||
|
||||
|
||||
if (debug == 1)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("OpenEnergyMonitor.org");
|
||||
Serial.print("emonTH FW: V"); Serial.println(version);
|
||||
Serial.print("emonTH FW: V");
|
||||
Serial.println(version);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
|
@ -216,12 +218,17 @@ void setup()
|
|||
load_config(); // Load RF config from EEPROM (if any exist)
|
||||
|
||||
// Add effect of DIP switch positions to nodeID
|
||||
if ((DIP1 == HIGH) && (DIP2 == HIGH)) nodeID=nodeID;
|
||||
if ((DIP1 == LOW) && (DIP2 == HIGH)) nodeID=nodeID+1;
|
||||
if ((DIP1 == HIGH) && (DIP2 == LOW)) nodeID=nodeID+2;
|
||||
if ((DIP1 == LOW) && (DIP2 == LOW)) nodeID=nodeID+3;
|
||||
if ((DIP1 == HIGH) && (DIP2 == HIGH))
|
||||
nodeID = nodeID;
|
||||
if ((DIP1 == LOW) && (DIP2 == HIGH))
|
||||
nodeID = nodeID + 1;
|
||||
if ((DIP1 == HIGH) && (DIP2 == LOW))
|
||||
nodeID = nodeID + 2;
|
||||
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
|
||||
// Send RFM69CW test sequence (for factory testing)
|
||||
for (int i = 10; i > -1; i--)
|
||||
|
|
@ -240,9 +247,12 @@ void setup()
|
|||
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");
|
||||
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);
|
||||
}
|
||||
|
|
@ -257,7 +267,8 @@ void setup()
|
|||
//################################################################################################################################
|
||||
// Setup and for presence of si7021
|
||||
//################################################################################################################################
|
||||
if (debug==1) Serial.println("Int SI7021..");
|
||||
if (debug == 1)
|
||||
Serial.println("Int SI7021..");
|
||||
|
||||
// check if the I2C lines are HIGH
|
||||
if (digitalRead(SDA) == HIGH || digitalRead(SCL) == HIGH)
|
||||
|
|
@ -267,40 +278,48 @@ void setup()
|
|||
if (deviceid != 0)
|
||||
{
|
||||
SI7021_status = 1;
|
||||
if (debug){
|
||||
if (debug)
|
||||
{
|
||||
si7021_env data = SI7021_sensor.getHumidityAndTemperature();
|
||||
Serial.print("SI7021 Started, ID: ");
|
||||
Serial.println(deviceid);
|
||||
Serial.print("SI7021 t: "); Serial.println(data.celsiusHundredths/100.0);
|
||||
Serial.print("SI7021 h: "); Serial.println(data.humidityBasisPoints/100.0);
|
||||
Serial.print("SI7021 t: ");
|
||||
Serial.println(data.celsiusHundredths / 100.0);
|
||||
Serial.print("SI7021 h: ");
|
||||
Serial.println(data.humidityBasisPoints / 100.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SI7021_status = 0;
|
||||
if (debug) Serial.println("SI7021 Error");
|
||||
if (debug)
|
||||
Serial.println("SI7021 Error");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SI7021_status = 0;
|
||||
if (debug) Serial.println("SI7021 Error");
|
||||
if (debug)
|
||||
Serial.println("SI7021 Error");
|
||||
}
|
||||
//################################################################################################################################
|
||||
// Setup and for presence of DS18B20
|
||||
//################################################################################################################################
|
||||
digitalWrite(DS18B20_PWR, HIGH); delay(50);
|
||||
digitalWrite(DS18B20_PWR, HIGH);
|
||||
delay(50);
|
||||
sensors.begin();
|
||||
sensors.setWaitForConversion(false); // disable automatic temperature conversion to reduce time spent awake, conversion will be implemented manually in sleeping http://harizanov.com/2013/07/optimizing-ds18b20-code-for-low-power-applications/
|
||||
numSensors = (sensors.getDeviceCount());
|
||||
byte j = 0; // search for one wire devices and
|
||||
// copy to device address arrays.
|
||||
while ((j < numSensors) && (oneWire.search(allAddress[j]))) j++;
|
||||
while ((j < numSensors) && (oneWire.search(allAddress[j])))
|
||||
j++;
|
||||
digitalWrite(DS18B20_PWR, LOW);
|
||||
|
||||
if (numSensors == 0)
|
||||
{
|
||||
if (debug==1) Serial.println("No DS18B20");
|
||||
if (debug == 1)
|
||||
Serial.println("No DS18B20");
|
||||
DS18B20 = 0;
|
||||
}
|
||||
else
|
||||
|
|
@ -308,11 +327,12 @@ void setup()
|
|||
DS18B20 = 1;
|
||||
if (debug == 1)
|
||||
{
|
||||
Serial.print(numSensors); Serial.println(" DS18B20");
|
||||
Serial.print(numSensors);
|
||||
Serial.println(" DS18B20");
|
||||
}
|
||||
}
|
||||
if (debug==1) delay(100);
|
||||
|
||||
if (debug == 1)
|
||||
delay(100);
|
||||
|
||||
//################################################################################################################################
|
||||
// Interrupt pulse counting setup
|
||||
|
|
@ -360,7 +380,8 @@ void setup()
|
|||
// Power Save - turn off what we don't need - http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
|
||||
//################################################################################################################################
|
||||
ACSR |= (1 << ACD); // disable Analog comparator
|
||||
if (debug==0) power_usart0_disable(); //disable serial UART
|
||||
if (debug == 0)
|
||||
power_usart0_disable(); // disable serial UART
|
||||
power_twi_disable(); // Two Wire Interface module:
|
||||
power_spi_disable();
|
||||
power_timer1_disable();
|
||||
|
|
@ -373,7 +394,6 @@ void setup()
|
|||
}
|
||||
} // end of setup
|
||||
|
||||
|
||||
//################################################################################################################################
|
||||
//################################################################################################################################
|
||||
void loop()
|
||||
|
|
@ -386,7 +406,8 @@ void loop()
|
|||
p = 0;
|
||||
}
|
||||
|
||||
if (Sleepy::loseSomeTime(WDT_PERIOD)==1) {
|
||||
if (Sleepy::loseSomeTime(WDT_PERIOD) == 1)
|
||||
{
|
||||
WDT_number++;
|
||||
}
|
||||
|
||||
|
|
@ -397,11 +418,12 @@ void loop()
|
|||
pulseCount = 0;
|
||||
sei();
|
||||
|
||||
|
||||
if (DS18B20 == 1)
|
||||
{
|
||||
digitalWrite(DS18B20_PWR, HIGH); dodelay(50);
|
||||
for(int j=0;j<numSensors;j++) sensors.setResolution(allAddress[j], TEMPERATURE_PRECISION); // and set the a to d conversion resolution of each.
|
||||
digitalWrite(DS18B20_PWR, HIGH);
|
||||
dodelay(50);
|
||||
for (int j = 0; j < numSensors; j++)
|
||||
sensors.setResolution(allAddress[j], TEMPERATURE_PRECISION); // and set the a to d conversion resolution of each.
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
dodelay(ASYNC_DELAY); // Must wait for conversion, since we use ASYNC mode
|
||||
|
||||
|
|
@ -439,7 +461,6 @@ void loop()
|
|||
power_twi_disable();
|
||||
}
|
||||
|
||||
|
||||
// Send data via RF
|
||||
if (RF_STATUS)
|
||||
{
|
||||
|
|
@ -462,36 +483,44 @@ void loop()
|
|||
digitalWrite(LED, LOW);
|
||||
}
|
||||
|
||||
|
||||
if (debug == 1)
|
||||
// Serial print strings pairs e.g. "temp:2634,humidity:4010,batt:33"
|
||||
// Works with EmonESP direct serial
|
||||
{
|
||||
Serial.print("temp:");Serial.print(emonth.temp); Serial.print(",");
|
||||
Serial.print("temp:");
|
||||
Serial.print(emonth.temp);
|
||||
Serial.print(",");
|
||||
|
||||
if (DS18B20)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Serial.print(",");
|
||||
Serial.print("pulse:"); Serial.print(emonth.pulsecount);
|
||||
Serial.print("pulse:");
|
||||
Serial.print(emonth.pulsecount);
|
||||
}
|
||||
Serial.println();
|
||||
delay(5);
|
||||
} // end serial print debug
|
||||
|
||||
|
||||
unsigned long last = now;
|
||||
now = millis();
|
||||
WDT_number = 0;
|
||||
|
|
@ -520,15 +549,15 @@ void onPulse()
|
|||
}
|
||||
|
||||
// Used to test for RFM69CW prescence
|
||||
static void writeReg (uint8_t addr, uint8_t value) {
|
||||
static void writeReg(uint8_t addr, uint8_t value)
|
||||
{
|
||||
RF69::control(addr | 0x80, value);
|
||||
}
|
||||
|
||||
static uint8_t readReg (uint8_t addr) {
|
||||
static uint8_t readReg(uint8_t addr)
|
||||
{
|
||||
return RF69::control(addr, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // IMPORTANT LINE! end unit test
|
||||
// http://docs.platformio.org/en/stable/plus/unit-testing.html
|
||||
|
|
|
|||
Loading…
Reference in New Issue