Temperature not presented to controller



  • Hi there,

    I've got this sketch running on a Arduino Nano with a 5V 2.1A powersupply and I cannot get the Temp presented to the gateway.

    Below is my sketch and my debug-log:

    sensor started, id 4
    send: 4-4-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
    send: 4-4-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 4-1-0 s=255,c=3,t=6,pt=1,l=1:0
    read: 4-1-0 s=255,c=3,t=6,pt=1,l=1:0
    read: 0-0-4 s=255,c=3,t=6,pt=0,l=1:M
    send: 4-4-0-0 s=255,c=3,t=11,pt=0,l=8,st=ok:Whatever
    send: 4-4-0-0 s=255,c=3,t=12,pt=0,l=1,st=ok:7
    send: 4-4-0-0 s=0,c=0,t=16,pt=0,l=0,st=ok:
    send: 4-4-0-0 s=1,c=0,t=16,pt=0,l=0,st=fail:
    send: 4-4-0-0 s=2,c=0,t=16,pt=0,l=0,st=fail:
    send: 4-4-0-0 s=8,c=0,t=6,pt=0,l=0,st=fail:
    send: 4-4-0-0 s=3,c=0,t=0,pt=0,l=0,st=fail:
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:487
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:430
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0
    new parent=0, d=1
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:386
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:353
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:335
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:350
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:350
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:332
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:347
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:351
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:333
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:348
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:349
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:331
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0
    new parent=0, d=1
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:346
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:349
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:330
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:350
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:331
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:346
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:351
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:332
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:348
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:348
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:330
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:345
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:349
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:330
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:327
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:343
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:349
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:331
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:327
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0
    new parent=0, d=1
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:343
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:346
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:327
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:343
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:344
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:326
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=ok:341
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=ok:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:347
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:328
    send: 4-4-0-0 s=2,c=1,t=23,pt=2,l=2,st=fail:344
    send: 4-4-0-0 s=3,c=1,t=16,pt=2,l=2,st=fail:0
    send: 4-4-0-0 s=8,c=1,t=0,pt=7,l=5,st=fail:-127.0
    send: 4-4-0-0 s=0,c=1,t=23,pt=2,l=2,st=fail:344
    send: 4-4-0-0 s=1,c=1,t=23,pt=2,l=2,st=fail:325
    send: 4-4-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 4-1-255 s=255,c=3,t=7,pt=0,l=0:
    read: 0-0-4 s=255,c=3,t=8,pt=1,l=1:0```]
    
    
    ```#include <SPI.h>
    #include <MySensor.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Bounce2.h>
    
    #define LIGHT_SENSOR_ANALOG_PIN_0 0 // Wasmachine
    #define LIGHT_SENSOR_ANALOG_PIN_1 1 // Droger
    #define LIGHT_SENSOR_ANALOG_PIN_2 2 // Zon
    #define BUTTON_PIN_1 3 // Balkondeur
    #define TEMP_1 8 // Pin where dallas sensor is connected
    
    unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
    
    OneWire oneWire(TEMP_1);
    DallasTemperature sensors(&oneWire);
    boolean metric = true;
    
    MySensor gw;
    MyMessage msgW(LIGHT_SENSOR_ANALOG_PIN_0,V_LIGHT_LEVEL);
    MyMessage msgD(LIGHT_SENSOR_ANALOG_PIN_1,V_LIGHT_LEVEL);
    MyMessage msgZ(LIGHT_SENSOR_ANALOG_PIN_2,V_LIGHT_LEVEL);
    MyMessage msgTemp(TEMP_1,V_TEMP);
    MyMessage msgBD(BUTTON_PIN_1,V_TRIPPED);
    
    void setup()
    {
      gw.begin();
      // Startup OneWire
      sensors.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Whatever", "7");
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(LIGHT_SENSOR_ANALOG_PIN_0,S_LIGHT_LEVEL);
      gw.present(LIGHT_SENSOR_ANALOG_PIN_1,S_LIGHT_LEVEL);
      gw.present(LIGHT_SENSOR_ANALOG_PIN_2,S_LIGHT_LEVEL);
      gw.present(TEMP_1,S_TEMP);
      gw.present(BUTTON_PIN_1,S_DOOR);
      
      pinMode(BUTTON_PIN_1,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN_1,HIGH);
    }
    
    void loop()
    {
      //Read temp from sensor
      sensors.requestTemperatures();
      float temperature = static_cast<float>(static_cast<int> (sensors.getTempCByIndex(TEMP_1) * 10.)) / 10.;
      gw.send(msgTemp.set(temperature, 1));
      //delay(5000);
      
      int lightLevel0 = analogRead(LIGHT_SENSOR_ANALOG_PIN_0);
      //delay(5000);
      int lightLevel1 = analogRead(LIGHT_SENSOR_ANALOG_PIN_1);
      //delay(5000);
      int lightLevel2 = analogRead(LIGHT_SENSOR_ANALOG_PIN_2);
      //delay(5000);
      //Serial.println(lightLevel0);
      //Serial.println(lightLevel1);
      //Serial.println(lightLevel2);
      gw.send(msgW.set(lightLevel0));
      gw.send(msgD.set(lightLevel1));
      gw.send(msgZ.set(lightLevel2));
      gw.send(msgBD.set(BUTTON_PIN_1==HIGH ? 1 : 0));
    
      
      gw.sleep(SLEEP_TIME);
    }
    

    I'm using 1.4 version in combination with a Arduino Gateway Nano.

    Everything else is presented to the controller but not the temperature.
    When I build a sketch with only the temp it works but that differs from this code above.


  • Hero Member

    You might try to add a capacitor between radio's VCC/GND, if not yet. Another try is to add a gw.wait(100) after each gw.send() (this made the trick for me).
    If after that you still getting a lot of st=fails, try replacing PSU / radio.



  • Cap is present and I will proceed to add a 100ms delay between those messages.
    Otherwise I will replace the radio.

    Let you know!



  • Implemented the wait time but no luck
    Replaced the radio and the cap but no luck
    Checked the wires but no luck

    Next thing is checking the code because the door is working and comes after the tempsensor.
    The reading of the tempsensor says -127.0

    Is there somebody who knows what kind of error -127.0 degrees means except my bedroom is very cold 😛


  • Admin





  • Boom! Got it!

    The sketch above does not send the temp because -127.0 / disconnected however with this sketch and implemented in my sketch above and it works...

    #include <MySensor.h>  
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 8 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) 30000 orig
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    MySensor gw;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    boolean metric = true; 
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    
    void setup()  
    { 
      // Startup OneWire 
      sensors.begin();
    
      // Startup and initialize MySensors library. Set callback for incoming messages. 
      //gw.begin(); 
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("test temp");
    
      // 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++) {   
         gw.present(i, V_TEMP);
      }
    }
    
    
    void loop()     
    {     
      // Process incoming messages (like config from server)
      gw.process(); 
    
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures(); 
    
      // 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>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
     
        // Only send data if temperature has changed more then 1 degC and no error
        if (int(lastTemperature[i]) != int(temperature) && temperature != -127.00) { //added integer
     
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature,1));
          lastTemperature[i]=temperature;
        }
      }
      //gw.sleep(SLEEP_TIME);
    }
    

    Same hardware, same libs and different code...
    You tell me whats wrong because I don't know it anymore...


Log in to reply
 

Suggested Topics

17
Online

11.4k
Users

11.1k
Topics

112.7k
Posts