I found the solution myself. About a week ago i upgraded the binding. And it worked.
Everything seems to work as it should. Except I can't recieve var1 (custom) for neither the hum or temp child.
smartSleep is nice. I use it once an hour (regular sleep every minute) to get configurations from openhab about sleep time and other small things in the code.
@balder88 said in openHAB 2.0 binding:
Hey guys, first message on this forum. Been reading alot before. But now I have a problem I just can't solve.
It's about smartsleep with openhab 2.
Im using wifi gw rfm 69.
Regular messages works as it should both ways.
But it almost seems like the smartsleep isn't enabled in the binding.
Here are my configs and logs.Things file:
Bridge mysensors:bridge-eth:gw69 [ ipAddress="192.168.1.235", tcpPort=5003, sendDelay=100, enableNetworkSanCheck=true ] { // Anarduino humidity AnHum [ nodeId="66", childId="0" ] temperature AnTemp [ nodeId="66", childId="1" ] light light02 [ nodeId="66", childId="3", smartSleep=true ] }
Items file:
Switch TestLight "Test lampa" (Test) { channel="mysensors:light:gw69:light02:status" }
Sketch: (Cleaned up the parts that dont matter, RTC and so on.)
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RFM69 #define MY_IS_RFM69HW #define MY_NODE_ID 66 #define MY_RFM69_NETWORKID 100 #define MY_RFM69_FREQUENCY RF69_433MHZ #define MY_SMART_SLEEP_WAIT_DURATION_MS 1000 #include <MySensors.h> #include <TimeLib.h> #include <Wire.h> #include <MCP7940RTC.h> #include <DHT.h> #define MCP7940_CTRL_ID 0x6F #define CSMEM_PIN 5 #define LEDPIN 9 long sleepIntervalSec=5; long loopCnt=0; uint8_t d[8]; uint8_t dAlarm[8]; int d1[8]; // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 6 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 5000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MULTIMETER 2 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgVolt(CHILD_ID_MULTIMETER, V_VOLTAGE); DHT dht; int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0; int batteryBasement = 812; int batteryFull = 922; float batteryConstant = 100.0 / (batteryFull - batteryBasement); float lastbatteryV = 0; const int buzzer = 7; //buzzer to arduino pin 7 #define RELAY_1 8 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay void before() { for (int sensor=3, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { // use the 1.1 V internal reference analogReference(INTERNAL); pinMode(LEDPIN, OUTPUT); digitalWrite(LEDPIN, LOW); Wire.begin(); pinMode(CSMEM_PIN, OUTPUT); digitalWrite(CSMEM_PIN, HIGH); 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) sleepIntervalSec = dht.getMinimumSamplingPeriod(); clearAlarm(); delay(20); setNewAlarm(); sleep(dht.getMinimumSamplingPeriod()); analogRead(BATTERY_SENSE_PIN); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Humidity sensor", "1.0"); present(CHILD_ID_MULTIMETER, S_MULTIMETER, "VOLT", true); present(CHILD_ID_HUM, S_HUM, "HUMIDITY", true); present(CHILD_ID_TEMP, S_TEMP, "TEMP", true); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } metric = getControllerConfig().isMetric; } void loop() { wait(100); int sensorValue = analogRead(BATTERY_SENSE_PIN); #ifdef MY_DEBUG Serial.println(sensorValue); #endif float batteryV = sensorValue * 0.004551646; if(sensorValue < batteryBasement) { sensorValue = batteryBasement; batteryV = 0; } else if (sensorValue > batteryFull) { sensorValue = batteryFull; } int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant; if ((abs(oldBatteryPcnt - batteryPcnt) > 1)) { sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; } if(batteryV != lastbatteryV) { send(msgVolt.set(batteryV, 2)); lastbatteryV = batteryV; } #ifdef MY_DEBUG Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // 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++; } long sleepTime = UPDATE_INTERVAL; if (batteryPcnt < 50) { sleepTime = (sleepTime * 2); } // Sleep for a while to save energy sleepIntervalSec = sleepTime / 1000; Serial.println(); Serial.print("Setting new sleep time: "); Serial.print(sleepIntervalSec); Serial.println(" seconds."); clearAlarm(); delay(20); setNewAlarm(); smartSleep(sleepTime); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
Sensor startup:
0 MCO:BGN:INIT NODE,CP=RRNNA--,VER=2.1.1 3 MCO:BGN:BFR 4 TSM:INIT 5 TSF:WUR:MS=0 8 TSM:INIT:TSP OK 9 TSM:INIT:STATID=66 11 TSF:SID:OK,ID=66 13 TSM:FPAR 143 TSF:MSG:SEND,66-66-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 524 TSF:MSG:READ,0-0-66,s=255,c=3,t=8,pt=1,l=1,sg=0:0 529 TSF:MSG:FPAR OK,ID=0,D=1 2150 TSM:FPAR:OK 2151 TSM:ID 2152 TSM:ID:OK 2154 TSM:UPL 2161 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2181 TSF:MSG:READ,0-0-66,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2186 TSF:MSG:PONG RECV,HP=1 2189 TSM:UPL:OK 2190 TSM:READY:ID=66,PAR=0,DIS=1 2199 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2253 TSF:MSG:READ,0-0-66,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2310 TSF:MSG:SEND,66-66-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 2366 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2403 TSF:MSG:READ,0-0-66,s=255,c=3,t=6,pt=0,l=1,sg=0:M 2461 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=11,pt=0,l=15,sg=0,ft=0,st=OK:Humidity sensor 2562 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0 2618 TSF:MSG:SEND,66-66-0-0,s=2,c=0,t=30,pt=0,l=4,sg=0,ft=0,st=OK:VOLT 2757 !TSF:MSG:SEND,66-66-0-0,s=0,c=0,t=7,pt=0,l=8,sg=0,ft=0,st=NACK:HUMIDITY 2777 TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=6,pt=0,l=4,sg=0,ft=1,st=OK:TEMP 2912 !TSF:MSG:SEND,66-66-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=NACK: 2918 MCO:REG:REQ 2974 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2 2991 TSF:MSG:READ,0-0-66,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2996 MCO:PIM:NODE REG=1 2999 MCO:BGN:STP 3154 MCO:SLP:MS=2000,SMS=0,I1=255,M1=255,I2=255,M2=255 3160 MCO:SLP:TPD 3161 MCO:SLP:WUP=-1 3163 MCO:BGN:INIT OK,TSP=1
Log Sensor: (This is when I press the button when the sensor is awake)
It's sends away it's heartbeat correctly.125578 TSF:MSG:READ,0-0-66,s=3,c=1,t=2,pt=0,l=1,sg=0:0 Incoming change for sensor:3, New status: 0 Setting new sleep time: 5 seconds. 137926 MCO:SLP:MS=5000,SMS=1,I1=255,M1=255,I2=255,M2=255 137939 TSF:MSG:SEND,66-66-0-0,s=255,c=3,t=22,pt=5,l=4,sg=0,ft=0,st=OK:134932
Log Openhab: And the gateway receives heartbeat.
18:21:37.174 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0 18:21:37.178 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'TestLight' received command OFF 18:21:37.181 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF 18:22:15.416 [DEBUG] [rs.internal.protocol.MySensorsReader] - 66;255;3;0;22;134932 18:22:16.372 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 0;0;3;0;2; 18:22:16.408 [DEBUG] [rs.internal.protocol.MySensorsReader] - 0;255;3;0;2;2.1.1
Log Openhab: When the node sleeps..
18:26:52.396 [DEBUG] [rs.internal.protocol.MySensorsWriter] - Sending to MySensors: 66;3;1;0;2;0 18:26:52.397 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'TestLight' received command OFF 18:26:52.399 [INFO ] [marthome.event.ItemStateChangedEvent] - TestLight changed from ON to OFF
As you can see there is no mention in the openhab log file about buffering or smart sleep. Or a received heartbeat. Which it gets.
What am I doing wrong?