So after running this weather station for a few weeks i decided to switch out the lux sensor for a soil moisture sensor without modifying the code....
The readings are working but they are very up and down.... they are not a steady decline..... how are people measuring the analog values of soil moisture ?
Posts made by JCH
-
RE: Sketch problems.... I think
-
RE: Help with pool solar controller code
Edit.... Does mysensors use pin 9 for anything? as soon as i try to use it as an input the radio seems to not be communicating with the controller?
I loaded a bounce sketch to test the button and pin and it works fine untill i reload my sketch. -
RE: Help with pool solar controller code
Ok i need help again please... I cannot get to the bottom of my last little problem......
void setup() { pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN, HIGH); pinMode(BUTTON_PIN_2, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_2, HIGH); // pinMode(BUTTON_PIN_3, INPUT); // Activate internal pull-up // digitalWrite(BUTTON_PIN_3, HIGH); debouncer.attach(BUTTON_PIN); debouncer.interval(5); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(5); debouncer3.attach(BUTTON_PIN_3); debouncer3.interval(5); oldValue = debouncer.read(); oldValue2 = debouncer2.read(); oldValue3 = debouncer3.read();
As soon as i tired to add a 3rd button and debouncer the whole code crashes.... as soon a a comment out the above lines it goes good again.... thoughts?
Here is the whole code (havent tidyed it up yet
/** JH REV 1.0 - 12-04-2020 */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_NODE_ID 22 //////////FOR TESTING #define MY_REPEATER_FEATURE #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <LiquidCrystal_I2C.h> #include <Bounce2.h> #include <SPI.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_PIN 4 #define RELAY_PIN_2 5 #define RELAY_PIN_3 6 #define RELAY_ON 0 #define RELAY_OFF 1 #define BUTTON_PIN 7 #define BUTTON_PIN_2 8 #define BUTTON_PIN_3 9 #define CHILD_ID 4 // Id of the sensor child for 1st relay #define CHILD_ID_2 5 // Id of the sensor child for 2nd relay #define CHILD_ID_3 6 // Id of the sensor child for 2nd relay bool state; Bounce debouncer = Bounce(); int oldValue=0; int oldValue1=0; bool state1; Bounce debouncer2 = Bounce(); int oldValue2=0; bool state2; Bounce debouncer3 = Bounce(); int oldValue3=0; bool state3; bool initialValueSent = false; unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) unsigned long CHECK_TIME = millis(); OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; float roofTemp; float poolTemp; String poolPumpstate; String solarPumpstate; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(1,V_TEMP); MyMessage msg2(CHILD_ID, V_LIGHT); MyMessage msg3(CHILD_ID_2, V_LIGHT); MyMessage msg4(CHILD_ID_3, V_LIGHT); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN, HIGH); pinMode(BUTTON_PIN_2, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_2, HIGH); // pinMode(BUTTON_PIN_3, INPUT); // Activate internal pull-up // digitalWrite(BUTTON_PIN_3, HIGH); debouncer.attach(BUTTON_PIN); debouncer.interval(5); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(5); debouncer3.attach(BUTTON_PIN_3); debouncer3.interval(5); oldValue = debouncer.read(); oldValue2 = debouncer2.read(); oldValue3 = debouncer3.read(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); lcd.begin(16, 2); // LCD 2 lines * 16 char. lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.setCursor(0, 0); lcd.clear(); lcd.print(" Contoller "); lcd.setCursor(0, 1); lcd.print(" Starting "); wait(2000); pinMode(RELAY_PIN, OUTPUT); pinMode(RELAY_PIN_2, OUTPUT); digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(RELAY_PIN_2, RELAY_OFF); /* lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); wait(2000); digitalWrite(RELAY_PIN, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Pool Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); wait(2000); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); digitalWrite(RELAY_PIN_2, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN_2, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Solar Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); */ wait(2000); wait(10000); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pool Controller", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); present(CHILD_ID, S_BINARY); present(CHILD_ID_2, S_BINARY); } } void loop() { if (!initialValueSent) { Serial.println("Sending initial value"); send(msg2.set(state?RELAY_OFF:RELAY_ON)); send(msg3.set(state?RELAY_OFF:RELAY_ON)); Serial.println("Requesting initial value from controller"); request(CHILD_ID, V_STATUS); request(CHILD_ID_2, V_STATUS); wait(2000, C_SET, V_STATUS); } debouncer.update(); debouncer2.update(); // Get the update value int value1 = debouncer.read(); int value2 = debouncer2.read(); if (debouncer.fell()) { state1 = !state1; send(msg2.set(state1?true:false), false); // Send new state and request ack back digitalWrite(RELAY_PIN, state1?RELAY_ON:RELAY_OFF); // TURN ON / OFF RELAYS oldValue1 = value1; } if (debouncer2.fell()) { state2 = !state2; send(msg3.set(state2?true:false), false); // Send new state and request ack back digitalWrite(RELAY_PIN_2, state2?RELAY_ON:RELAY_OFF); // TURN ON / OFF RELAYS oldValue2 = value2; } unsigned long NOW_TIME = millis(); if(NOW_TIME - CHECK_TIME >= SLEEP_TIME) { updateLCDtemps(); CHECK_TIME = NOW_TIME; Serial.println("Updating LCD"); } updateTemperature(30); if (solarPumpstate == "Running" ){ updateLCDstatus; } } /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE TEMPS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void receive(const MyMessage &message) { if (message.type==V_TEMP) { if (message.sensor == 1) { // Write some debug info Serial.print("Incoming change from roof sensor:"); Serial.print(message.sensor); Serial.print("\n"); Serial.print(", New status: "); Serial.println(message.getFloat()); roofTemp = (message.getFloat()); }} /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE RELAYS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// else if (message.getType()==V_STATUS) { if (message.sensor == 4){ state1 = message.getBool(); digitalWrite(RELAY_PIN, state1?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); // send(msg2.set(state?RELAY_ON:RELAY_OFF)); if ((message.getBool())== 1){ poolPumpstate = ("Running");} else{ poolPumpstate = ("Standby"); }} if (message.sensor == 5){ state2 = message.getBool(); Serial.print(state); digitalWrite(RELAY_PIN_2, state2?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); // send(msg3.set(state?RELAY_OFF:RELAY_ON)); if ((message.getBool())== 1){ solarPumpstate = ("Running");} else{ solarPumpstate = ("Standby"); }} if (message.type == V_STATUS) { if (!initialValueSent) { Serial.println("Receiving initial value from controller"); initialValueSent = true; }} } } void updateLCDtemps() { lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolTemp); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(roofTemp); lcd.print((char)223); lcd.print("C"); } void updateLCDstatus() { lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolPumpstate); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(solarPumpstate); } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { Serial.println("Updating Dallas Temp"); sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; poolTemp = temperature; Serial.println("Pool Temp = "); Serial.println(poolTemp); updateLCDtemps(); } } lastUpdateTime += frequency * 1000UL; } }
-
RE: Help with pool solar controller code
@skywatch Good advice.. I will do that today.
Thanks -
RE: Help with pool solar controller code
@skywatch Will the interrupt work with wait or only sleep?
I ended up going down a rabbit hole trying to implement a non breaking timer as below... it all seems to be working now except the button doesnt switch states everytime.... sometimes have to press it 2 or 3 times?/** JH REV 1.0 - 12-04-2020 */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_NODE_ID 2 //////////FOR TESTING #define MY_REPEATER_FEATURE #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <LiquidCrystal_I2C.h> #include <Bounce2.h> #include <SPI.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_PIN 4 #define RELAY_PIN_2 5 #define RELAY_ON 0 #define RELAY_OFF 1 #define BUTTON_PIN 7 #define BUTTON_PIN_2 8 #define CHILD_ID 4 // Id of the sensor child for 1st relay #define CHILD_ID_2 5 // Id of the sensor child for 2nd relay bool state; Bounce debouncer = Bounce(); int oldValue=0; bool state1; Bounce debouncer2 = Bounce(); int oldValue2; bool state2; bool initialValueSent = false; unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) unsigned long CHECK_TIME = millis(); OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; float roofTemp; float poolTemp; String poolPumpstate; String solarPumpstate; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(1,V_TEMP); MyMessage msg2(CHILD_ID, V_LIGHT); MyMessage msg3(CHILD_ID_2, V_LIGHT); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN, HIGH); pinMode(BUTTON_PIN_2, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_2, HIGH); debouncer.attach(BUTTON_PIN); debouncer.interval(5); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(5); oldValue = debouncer.read(); oldValue2 = debouncer2.read(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); lcd.begin(16, 2); // LCD 2 lines * 16 char. lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.setCursor(0, 0); lcd.clear(); lcd.print(" Contoller "); lcd.setCursor(0, 1); lcd.print(" Starting "); wait(2000); pinMode(RELAY_PIN, OUTPUT); pinMode(RELAY_PIN_2, OUTPUT); digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(RELAY_PIN_2, RELAY_OFF); /* lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); wait(2000); digitalWrite(RELAY_PIN, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Pool Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); wait(2000); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); digitalWrite(RELAY_PIN_2, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN_2, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Solar Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); */ wait(2000); wait(10000); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pool Controller", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); present(CHILD_ID, S_BINARY); present(CHILD_ID_2, S_BINARY); } } void loop() { if (!initialValueSent) { Serial.println("Sending initial value"); send(msg2.set(state?RELAY_OFF:RELAY_ON)); send(msg3.set(state?RELAY_OFF:RELAY_ON)); Serial.println("Requesting initial value from controller"); request(CHILD_ID, V_STATUS); request(CHILD_ID_2, V_STATUS); wait(2000, C_SET, V_STATUS); } { debouncer.update(); // Get the update value int value = debouncer.read(); state = !state; if (value != oldValue && value==0) { send(msg2.set(state?true:false), true); // Send new state and request ack back digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); } oldValue = value; /* { debouncer2.update(); // Get the update value int value = debouncer2.read(); state2 = !state2; if (value != oldValue2 && value==0) { send(msg3.set(state2?true:false), false); // Send new state and request ack back digitalWrite(RELAY_PIN_2, state2?RELAY_ON:RELAY_OFF); } oldValue = value; }*/ } unsigned long NOW_TIME = millis(); if(NOW_TIME - CHECK_TIME >= SLEEP_TIME) { updateLCDtemps(); CHECK_TIME = NOW_TIME; Serial.println("Updating LCD"); } updateTemperature(30); if (solarPumpstate == "Running" ){ updateLCDstatus; } } /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE TEMPS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void receive(const MyMessage &message) { if (message.type==V_TEMP) { if (message.sensor == 1) { // Write some debug info Serial.print("Incoming change from roof sensor:"); Serial.print(message.sensor); Serial.print("\n"); Serial.print(", New status: "); Serial.println(message.getFloat()); roofTemp = (message.getFloat()); }} /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE RELAYS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// else if (message.getType()==V_STATUS) { if (message.sensor == 4){ state = message.getBool(); Serial.print(state); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); // send(msg2.set(state?RELAY_ON:RELAY_OFF)); if ((message.getBool())== 1){ poolPumpstate = ("Running");} else{ poolPumpstate = ("Standby"); }} if (message.sensor == 5){ state = (bool)message.getInt(); Serial.print(state); digitalWrite(RELAY_PIN_2, state?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); send(msg3.set(state?RELAY_OFF:RELAY_ON)); if ((message.getBool())== 1){ solarPumpstate = ("Running");} else{ solarPumpstate = ("Standby"); }} if (message.type == V_STATUS) { if (!initialValueSent) { Serial.println("Receiving initial value from controller"); initialValueSent = true; }} } } void updateLCDtemps() { lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolTemp); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(roofTemp); lcd.print((char)223); lcd.print("C"); } void updateLCDstatus() { lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolPumpstate); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(solarPumpstate); } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; poolTemp = temperature; } } lastUpdateTime += frequency * 1000UL; } }
-
RE: Help with pool solar controller code
EDIT: I think the push button wont work if there is a wait for sleep.... Is there anyway around this?
-
RE: Help with pool solar controller code
@skywatch
The 30 seconds is while im only testing it.... once it is working as expected i will change the time -
RE: Help with pool solar controller code
Ok i am stuck again.....
I cant seem to get the push buttons to activate the relays.....
What am i doing wrong?/** JH REV 1.0 - 12-04-2020 */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_NODE_ID 50 //////////FOR TESTING #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <LiquidCrystal_I2C.h> #include <Bounce2.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_PIN 4 #define RELAY_PIN_2 5 #define RELAY_ON 0 #define RELAY_OFF 1 #define BUTTON_PIN_1 7 #define BUTTON_PIN_2 8 #define CHILD_ID 4 // Id of the sensor child for 1st relay #define CHILD_ID_2 5 // Id of the sensor child for 2nd relay Bounce debouncer = Bounce(); Bounce debouncer2 = Bounce(); int oldValue=-1; int oldValue2=-1; bool state ; bool state2 ; bool initialValueSent = false; unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; float roofTemp; float poolTemp; String poolPumpstate; String solarPumpstate; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(1,V_TEMP); MyMessage msg2(CHILD_ID, V_LIGHT); MyMessage msg3(CHILD_ID_2, V_LIGHT); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { pinMode(BUTTON_PIN_1,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_1,HIGH); pinMode(BUTTON_PIN_2,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_2,HIGH); debouncer.attach(BUTTON_PIN_1); debouncer.interval(5); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(5); oldValue = debouncer.read(); oldValue2 = debouncer2.read(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); lcd.begin(16, 2); // LCD 2 lines * 16 char. lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.setCursor(0, 0); lcd.clear(); lcd.print(" Contoller "); lcd.setCursor(0, 1); lcd.print(" Starting "); wait(2000); pinMode(RELAY_PIN, OUTPUT); pinMode(RELAY_PIN_2, OUTPUT); digitalWrite(RELAY_PIN, RELAY_OFF); digitalWrite(RELAY_PIN_2, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); wait(2000); digitalWrite(RELAY_PIN, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Pool Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); wait(2000); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Begin Pump Test"); digitalWrite(RELAY_PIN_2, RELAY_ON); wait(5000); digitalWrite(RELAY_PIN_2, RELAY_OFF); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Solar Pump Test"); lcd.setCursor(0, 1); lcd.print("OK"); wait(2000); wait(10000); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pool Controller", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); present(CHILD_ID, S_BINARY); present(CHILD_ID_2, S_BINARY); } } void loop() { /////////////////////////////////////////////////////////////////////////////////////// /////////////////// REQUEST AND SEND INITIAL VALUES FOR RELAYS ////////////////////// /////////////////////////////////////////////////////////////////////////////////////// if (!initialValueSent) { Serial.println("Sending initial value"); send(msg2.set(state?RELAY_OFF:RELAY_ON)); send(msg3.set(state?RELAY_OFF:RELAY_ON)); Serial.println("Requesting initial value from controller"); request(CHILD_ID, V_STATUS); request(CHILD_ID_2, V_STATUS); wait(2000, C_SET, V_STATUS); } /////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// MAIN LOOP //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// { debouncer.update(); debouncer2.update(); // Get the update value int value = debouncer.read(); int value2 = debouncer2.read(); if (value != oldValue) { state = !state; // Toggle the state send(msg.set(state), false); // send new state to controller, no ack requested digitalWrite(RELAY_PIN, state); // switch the relay to the new state oldValue = value; } if (value2 != oldValue2) { state2 = !state2; // Toggle the state send(msg2.set(state2), false); // send new state to controller, no ack requested digitalWrite(RELAY_PIN_2, state2); // switch the relay to the new state oldValue2 = value2; } // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) wait(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; poolTemp = temperature; } } wait(1000); } updateLCD(); } /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE TEMPS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void receive(const MyMessage &message) { if (message.type==V_TEMP) { if (message.sensor == 1) { // Write some debug info Serial.print("Incoming change from roof sensor:"); Serial.print(message.sensor); Serial.print("\n"); Serial.print(", New status: "); Serial.println(message.getFloat()); roofTemp = (message.getFloat()); }} /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE RELAYS //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// else if (message.getType()==V_STATUS) { if (message.sensor == 4){ state = (bool)message.getInt(); Serial.print(state); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); send(msg2.set(state?RELAY_OFF:RELAY_ON)); if ((message.getBool())== 1){ poolPumpstate = ("Running");} else{ poolPumpstate = ("Standby"); }} if (message.sensor == 5){ state = (bool)message.getInt(); Serial.print(state); digitalWrite(RELAY_PIN_2, state?RELAY_ON:RELAY_OFF); Serial.print("Incoming change for sensor:"); Serial.print(message.getSensor()); Serial.print(", New status: "); Serial.println(message.getBool()); send(msg3.set(state?RELAY_OFF:RELAY_ON)); if ((message.getBool())== 1){ solarPumpstate = ("Running");} else{ solarPumpstate = ("Standby"); }} if (message.type == V_STATUS) { if (!initialValueSent) { Serial.println("Receiving initial value from controller"); initialValueSent = true; }} }} void updateLCD() { lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolTemp); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(roofTemp); lcd.print((char)223); lcd.print("C"); wait(10000); lcd.clear(); lcd.print(" Pump Status"); wait(2000); lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool :"); lcd.print(" "); lcd.print(poolPumpstate); lcd.setCursor(0, 0); lcd.print("Solar :"); lcd.print(" "); lcd.print(solarPumpstate); wait(10000); lcd.clear(); lcd.print(" Temperatures"); wait(2000); }
-
RE: Help with pool solar controller code
Thanks @BearWithBeard
Ok how does this look.......
/** * 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 * * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller * http://www.mysensors.org/build/temp */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_NODE_ID 2 //#define MY_RADIO_RFM69 #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; int roofTemp; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(1,V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); lcd.begin(16, 2); // LCD 2 lines * 16 char. lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.setCursor(0, 0); lcd.print("Waiting for temperature updates"); wait(10000); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { /////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// MAIN LOOP //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) wait(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; lcd.clear(); lcd.setCursor(0, 1); lcd.print("Pool Temp:"); lcd.print(" "); lcd.print(temperature); lcd.setCursor(0, 0); lcd.print("Roof Temp:"); lcd.print(" "); lcd.print(roofTemp); } } } /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////// RECIEVE ROOF TEMP //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void receive(const MyMessage &message) { if (message.type==V_TEMP) { if (message.sensor <= 1) { // Write some debug info Serial.print("Incoming change from roof sensor:"); Serial.print(message.sensor); Serial.print("\n"); Serial.print(", New status: "); Serial.println(message.getFloat()); roofTemp = (message.getFloat()); } } }
One more question i need help with......
On the roof sensor , do i send the nodes different msg. or the same? -
Help with pool solar controller code
I am trying to create a pool solar controller and have run into a couple of issues which i cannot figure out as im not a very good coder
I am going to have a ds18b20 waterproof temp sensor in the pool pump shed which is taped to the pool pipe to reflect the pool temp.
This node is also going to have a lcd screen which displays the pool temp and well as the roof solar temp.
I am going to have a 2nd node on the roof measuring the roof water temp and that node is going to send its data back to the controller and also direct to the node (not sure if this is the best way or not) so that it can be displayed on the lcd screen.
The roof node is powered by solar and reports every 30 seconds and then goes back to sleep.Here is the code for the roof sensor
/** * 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 * * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller * http://www.mysensors.org/build/temp */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_LOW #define MY_NODE_ID 1 #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(0,V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // use the 1.1 V internal reference for battery mointor #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Roof Temperature Sensor", "1.0"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { ////////////////////////////////////////////// /////////// BATTERY CODE /////////////////// ///////////////////////////////////////////// // get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef MY_DEBUG Serial.println(sensorValue); #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 int batteryPcnt = sensorValue / 10; #ifdef MY_DEBUG float batteryV = sensorValue * 0.003363075; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; } ////////////////////////////////////////////// /////////// DALLAS CODE /////////////////// ///////////////////////////////////////////// // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature,1)); send(msg.setDestination(2).setSensor(1).set(temperature, 1)); // send the temp to Node 2(Pool temp) // Save new temperatures for next compare lastTemperature[i]=temperature; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } sleep(SLEEP_TIME); }
And here is the code for the pool controller so far.....
/** * 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 * * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller * http://www.mysensors.org/build/temp */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_NODE_ID 2 //#define MY_RADIO_RFM69 #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; bool receivedConfig = false; bool metric = true; // Initialize temperature message MyMessage msg(1,V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); lcd.begin(16, 2); // LCD 2 lines * 16 char. lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.setCursor(0, 0); lcd.print("Waiting for temperature updates"); wait(10000); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { //request(1, V_TEMP); // NO NEED TO REQUEST AS IT IS BEING SENT } void receive(const MyMessage &message) { if (message.type==V_TEMP) { if (message.sensor <= 1) { // Write some debug info Serial.print("Incoming change from roof sensor:"); Serial.print(message.sensor); Serial.print("\n"); Serial.print(", New status: "); Serial.println(message.getFloat()); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Roof Temp:"); lcd.print(" "); lcd.print(message.getFloat()); } // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; lcd.setCursor(0, 1); lcd.print("Pool Temp:"); lcd.print(" "); lcd.print(temperature); } } } // wait(SLEEP_TIME); }
Now the problem i am having is as the pool node doesn't sleep it basically just waits to receive a message from the pool controller and once it does it reports both sensors and then goes back to start again.... so if the roof node goes down for whatever reason then the whole thing stops working.
What is the best way around this?Also i wasnt getting alot of the messages and figured ouit from the logs that it was bcasue it was being repeated by the gateway... so to get around that i changed
if (message.sensor == 1)
to
if (message.sensor <= 1)
to include the gateway ( 0 )
again i am not sure if thats the best way forward?
I really am only a weekend hobbyist so not too sure that i am going about this the right way -
RE: Sketch problems.... I think
Turns out i had a bad battery...... Must of shorted internally and was causing my arduino to go crazy .
Node is up and running and reporting perfectly. Power consumption is approx 220uA.
Reporting temp, humidity, light level , barometer, forecast and battery level.
Here is the code if anyone wants................../** OUTDOOR WEATHER STATION SKETCH TEMP AND PRESSURE VIA BMP180 HUMIDITY VIA DHT22 LIGHT SENSOR VIA LM393 SOIL MOISTURE VIA SOIL MOISTURE SENSOR CREATED BY J.H 4.3.2020 REV 2 * */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 // Define Node ID #define MY_NODE_ID 5 // Includes #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <Adafruit_BMP085.h> #include <DHT.h> // Pin Defines #define DHT_DATA_PIN 2 #define LIGHT_SENSOR_ANALOG_PIN 1 #define LUX_ON 5 // Defines #define POWER_ON 1 // value to write to turn on sensor #define POWER_OFF 0 // value to write to turn off sensor #define BARO_CHILD 0 #define TEMP_CHILD 1 #define VOLTAGE_CHILD_ID 3 #define CHILD_ID_HUM 4 #define CHILD_ID_LIGHT 5 static const uint64_t UPDATE_INTERVAL = 30000; static const uint8_t FORCE_UPDATE_N_READS = 10; int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; const float ALTITUDE = 59; // <-- adapt this value to your own location's altitude. // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute. const unsigned long SLEEP_TIME = 60000; const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" }; enum FORECAST { STABLE = 0, // "Stable Weather Pattern" SUNNY = 1, // "Slowly rising Good Weather", "Clear/Sunny " CLOUDY = 2, // "Slowly falling L-Pressure ", "Cloudy/Rain " UNSTABLE = 3, // "Quickly rising H-Press", "Not Stable" THUNDERSTORM = 4, // "Quickly falling L-Press", "Thunderstorm" UNKNOWN = 5 // "Unknown (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor float lastPressure = -1; float lastTemp = -1; int lastForecast = -1; //float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; //bool metric = true; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h be dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; bool metric; MyMessage tempMsg(TEMP_CHILD, V_TEMP); MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage forecastMsg(BARO_CHILD, V_FORECAST); MyMessage voltageMsg(VOLTAGE_CHILD_ID, V_VOLTAGE); MyMessage msgHum(CHILD_ID_HUM, V_HUM); DHT dht; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { //Serial.println("Setting Pin Mode to Output"); //pinMode(LUX_ON, OUTPUT); Serial.println("Setup Sensor"); dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); { // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif } if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } metric = getConfig().isMetric; } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pressure Sensor", "1.1"); Serial.println("Present sensors to gateway"); // Register sensors to gw (they will be created as child devices) present(BARO_CHILD, S_BARO, "Pressure" ); present(TEMP_CHILD, S_TEMP, "Temperature" ); present(VOLTAGE_CHILD_ID, S_MULTIMETER, "Battery" ); present(CHILD_ID_HUM, S_HUM, "Humidity" ); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "Lux" ); // metric = getConfig().isMetric; } void loop() { //////////////////////////////////////// ////////// Lux Sensor Code ///////////// //////////////////////////////////////// digitalWrite(LUX_ON, POWER_ON); // Power the Lux sensor of Digital Pin to save power Serial.print("Sensor Power on pin "); Serial.print(LUX_ON); Serial.print(" is..."); Serial.println((POWER_ON)); wait(1000); // Wait a second for sensor to power up before reading int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println("Light Lux Level:"); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(msg.set(lightLevel)); lastLightLevel = lightLevel; digitalWrite(LUX_ON, POWER_OFF); // turn it off Serial.print("Sensor Power on pin "); Serial.print(LUX_ON); Serial.print(" is..."); Serial.println((POWER_OFF)); } wait(1000); //////////////////////////////////////// ////////// DHT22 Sensor Code /////////// //////////////////////////////////////// // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("Humidity: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy //sleep(UPDATE_INTERVAL); { ///////////////////////////////////////////// ////////// Battery Reporting Code /////////// ///////////////////////////////////////////// // get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef MY_DEBUG Serial.println(sensorValue); #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 int batteryPcnt = sensorValue / 10; #ifdef MY_DEBUG float batteryV = sensorValue * 0.003363075; float voltage = sensorValue * 0.003363075; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; send(voltageMsg.set(voltage,2)); } // sleep(SLEEP_TIME); } ////////////////////////////////////////////////// ////////// BMP180 Pressure Sensor Code /////////// ////////////////////////////////////////////////// float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; float temperature = bmp.readTemperature(); if (!metric) { // Convert to fahrenheit temperature = temperature * 9.0 / 5.0 + 32.0; } int forecast = sample(pressure); Serial.print("Temperature = "); Serial.print(temperature); Serial.println(metric ? " *C" : " *F"); Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); if (temperature != lastTemp) { send(tempMsg.set(temperature, 1)); lastTemp = temperature; } if (pressure != lastPressure) { send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } sleep(SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } ////////////////////////////////////////// ////////// Forecast Algorithm /////////// ///////////////////////////////////////// int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = UNKNOWN; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = UNKNOWN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWN; } // uncomment when debugging Serial.print(F("Forecast at minute ")); Serial.print(minuteCount); Serial.print(F(" dP/dt = ")); Serial.print(dP_dt); Serial.print(F("kPa/h --> ")); Serial.println(weather[forecast]); return forecast; }
-
Sketch problems.... I think
I am trying to create a outdoor weather station which runs on batterys.
I am having issues with the light level readings.... they were working fine now all of a sudden they arent.
I am pretty sure that it is an issue with my sketch but i cant find any problems?? Am i missing something??/** * 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 * Pressure sensor example using BMP085 module * http://www.mysensors.org/build/pressure * */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 5 #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <Adafruit_BMP085.h> #include <DHT.h> #define DHT_DATA_PIN 2 #define LIGHT_SENSOR_ANALOG_PIN 1 #define LUX_ON 5 #define POWER_ON 1 // value to write to turn on sensor #define POWER_OFF 0 // value to write to turn off sensor #define BARO_CHILD 0 #define TEMP_CHILD 1 #define VOLTAGE_CHILD_ID 3 #define CHILD_ID_HUM 4 #define CHILD_ID_LIGHT 5 static const uint64_t UPDATE_INTERVAL = 30000; static const uint8_t FORCE_UPDATE_N_READS = 10; int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; const float ALTITUDE = 59; // <-- adapt this value to your own location's altitude. // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute. const unsigned long SLEEP_TIME = 60000; const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" }; enum FORECAST { STABLE = 0, // "Stable Weather Pattern" SUNNY = 1, // "Slowly rising Good Weather", "Clear/Sunny " CLOUDY = 2, // "Slowly falling L-Pressure ", "Cloudy/Rain " UNSTABLE = 3, // "Quickly rising H-Press", "Not Stable" THUNDERSTORM = 4, // "Quickly falling L-Press", "Thunderstorm" UNKNOWN = 5 // "Unknown (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor float lastPressure = -1; float lastTemp = -1; int lastForecast = -1; //float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; //bool metric = true; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h be dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; bool metric; MyMessage tempMsg(TEMP_CHILD, V_TEMP); MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage forecastMsg(BARO_CHILD, V_FORECAST); MyMessage voltageMsg(VOLTAGE_CHILD_ID, V_VOLTAGE); MyMessage msgHum(CHILD_ID_HUM, V_HUM); DHT dht; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { //Serial.println("Setting Pin Mode to Output"); //pinMode(LUX_ON, OUTPUT); Serial.println("Setup Sensor"); dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); { // use the 1.1 V internal reference #if defined(__AVR_ATmega2560__) analogReference(INTERNAL1V1); #else analogReference(INTERNAL); #endif } if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } metric = getConfig().isMetric; } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Pressure Sensor", "1.1"); Serial.println("Present sensors to gateway"); // Register sensors to gw (they will be created as child devices) present(BARO_CHILD, S_BARO); present(TEMP_CHILD, S_TEMP); present(VOLTAGE_CHILD_ID, S_MULTIMETER, "Battery " ); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); // metric = getConfig().isMetric; } void loop() { int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println("LUX:"); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(msg.set(lightLevel)); lastLightLevel = lightLevel; } sleep(5000); Serial.println("Humidity"); // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy //sleep(UPDATE_INTERVAL); { // get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef MY_DEBUG Serial.println(sensorValue); #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 int batteryPcnt = sensorValue / 10; #ifdef MY_DEBUG float batteryV = sensorValue * 0.003363075; float voltage = sensorValue * 0.003363075; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; send(voltageMsg.set(voltage,2)); } // sleep(SLEEP_TIME); } float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; float temperature = bmp.readTemperature(); if (!metric) { // Convert to fahrenheit temperature = temperature * 9.0 / 5.0 + 32.0; } int forecast = sample(pressure); Serial.print("Temperature = "); Serial.print(temperature); Serial.println(metric ? " *C" : " *F"); Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); if (temperature != lastTemp) { send(tempMsg.set(temperature, 1)); lastTemp = temperature; } if (pressure != lastPressure) { send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } sleep(SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = UNKNOWN; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = UNKNOWN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWN; } // uncomment when debugging Serial.print(F("Forecast at minute ")); Serial.print(minuteCount); Serial.print(F(" dP/dt = ")); Serial.print(dP_dt); Serial.print(F("kPa/h --> ")); Serial.println(weather[forecast]); return forecast; }
EDIT: ignore the commented out sections.. i was playing around with powering the sensor off an arduino pin so try and save on power
-
RE: Trying to build a ethernet gateway but cant set an ip address
How do i find that out? Is it this below?
Sketch uses 24032 bytes (78%) of program storage space. Maximum is 30720 bytes.
Global variables use 964 bytes (47%) of dynamic memory, leaving 1084 bytes for local variables. Maximum is 2048 bytes. -
RE: Trying to build a ethernet gateway but cant set an ip address
Here is my gateway code
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 // Enable gateway ethernet module type #define MY_GATEWAY_W5100 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal) //#define MY_W5100_SPI_EN 4 // Enable Soft SPI for NRF radio (note different radio wiring is required) // The W5100 ethernet module seems to have a hard time co-operate with // radio on the same spi bus. #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD) #define MY_SOFTSPI #define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MOSI_PIN 15 #endif // When W5100 is connected we have to move CE/CSN pins for NRF radio #ifndef MY_RF24_CE_PIN #define MY_RF24_CE_PIN 5 #endif #ifndef MY_RF24_CS_PIN #define MY_RF24_CS_PIN 6 #endif // Enable UDP communication //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) #define MY_IP_ADDRESS 192,168,1,6 // If using static ip you can define Gateway and Subnet address as well #define MY_IP_GATEWAY_ADDRESS 192,168,1,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 // Renewal period if using DHCP //#define MY_IP_RENEWAL_INTERVAL 60000 // The port to keep open on node server mode / or port to contact in client mode #define MY_PORT 5003 // Controller ip address. Enables client mode (default is "server" mode). // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 5 //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org" // The MAC address can be anything you want but should be unique on your network. // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use. // Note that most of the Arduino examples use "DEAD BEEF FEED" for the MAC address. #define MY_MAC_ADDRESS 0xDE,0xAD,0xBE,0xEF,0xFE,0xED // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // 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 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err // Uncomment to override default HW configurations //#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin #if defined(MY_USE_UDP) #include <EthernetUdp.h> #endif #include <Ethernet.h> #include <MySensors.h> void setup() { // Setup locally attached sensors } void presentation() { // Present locally attached sensors here } void loop() { // Send locally attached sensors data here }
-
Trying to build a ethernet gateway but cant set an ip address
I have been running a serial gateway for quite a few years now but i have just built a ethernet gateway and am trying to get it up and running.....
Here is the output from the monitor.
MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2
4 TSM:INIT
5 TSF:WUR:MS=0
12 TSM:INIT:TSP OK
13 TSM:INIT:GW MODE
15 TSM:READY:ID=0,PAR=0,DIS=0
18 MCO:REG:NOT NEEDED
601 GWT:TIN:IP=5.0.0.0
1603 MCO:BGN:STP
1604 MCO:BGN:INIT OK,TSP=1
1607 TSM:READY:NWD REQ
1612 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
1903 TSF:MSG:READ,9-9-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
1911 TSF:MSG:READ,0-9-255,s=255,c=3,t=20,pt=0,l=0,sg=0:
1916 TSF:MSG:BC
1949 TSF:MSG:READ,14-9-0,s=3,c=1,t=16,pt=2,l=2,sg=0:0
1956 TSF:MSG:READ,11-9-0,s=255,c=3,t=21,pt=1,l=1,sg=0:9
2395 TSF:MSG:READ,14-9-0,s=255,c=3,t=21,pt=1,l=1,sg=0:9
2509 TSF:MSG:READ,10-9-0,s=255,c=3,t=21,pt=1,l=1,sg=0:9
2518 TSF:MSG:READ,10-9-0,s=255,c=3,t=21,pt=1,l=1,sg=0:9I cant seem to set an ip address, it keeps giving a random one each time i restart it. Any ideas?
-
RE: Raspberry Pi gateway and controller in one
Ok cool, thanks for the replys. I will give it a go and see how i get on
-
RE: Domotiocz + Rain gauge
Ok thanks for the reply.... I was only wanting to use your sketch as my node is battery powered and the mysensors example uses a lot of power as it doesn't sleep.
I will try and modify it. -
RE: Domotiocz + Rain gauge
Hi
I am using this sketch on my battery powered rain gauge but have noticed the gauge never resets, how are you managing this? i am using Vera as a controller -
Raspberry Pi gateway and controller in one
Has anyone successfully installed Home Assistant on a RPi and used the same pi as a Mysensors Gateway with a NRF module attached to the Pi?