Generic Temperature/repeater node



  • Hi Guys,

    I have several nodes up and running which I feed into Domoticz.

    I'm currently trying to turn the DallasTemperatureSensor script into a repeater node. I have built some plug-in temp sensors but I have range issues due to living in a "Faraday Mansion". Some of my internal walls are 700mm+ in thickness! My current "get around" is to have a Raspberry Pi + Arduino gateway connected to each wifi point (yeah wifi is a huge issue too!)

    So far I have
    gw.begin(NULL, AUTO, true);
    in the
    void setup()

    and I'm calling process() in my loop()

    But I don't know where to go with regard to sleep/wait etc.
    I'd like to take a temp reading every 10 - 15 mins but I'm stuck

    Any pointers? 😄


  • Hero Member

    Hi and welcome. You can try a non-blocking code loop like:

    if (millis() > lastUpdate + loopDelay){
        < whatever you want to do> ;
       lastUpdate = millis();
    }
    

    make sure you have the lastUpdate (and loopDelay) as unisigned long

    • or -

    use gw.wait() ;



  • Thanks for the reply!

    I got my "Arduino for Dummies" book from Amazon today... sooo let's give it a go 🙂



  • Ok... I tried this based on the standard dallas DS18B20 sketch and I think it's working.

    It shows up in MSController as both a TEMP sensor and an ARDUINO_RELAY

    Tomorrow I'll try it with Domoticz

    Many thanks for the advice 😉

    #include <MySensor.h>  
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #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 WAIT_TIME = 300000; // Wait 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. 
    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 up the OneWire library
      sensors.begin();
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    
      // Startup and initialize MySensors library. Set callback for incoming messages. 
      gw.begin(NULL, AUTO, true);
    
      // Send the sketch version information to the gateway and Controller
      gw.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++) {   
         gw.present(i, S_TEMP);
      }
    }
    
    
    void loop()     
    {     
      // Process incoming messages (like config from server)
      gw.process(); 
    
      // 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)
      gw.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>((gw.getConfig().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
          gw.send(msg.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
      }
      gw.wait(WAIT_TIME);
    }


  • Ah... actually it doesn't work 😞
    It takes one temp reading and then sits there with a led flashing... damn!

    Anyone see the problem?


  • Hero Member

    @blackdog65 You can include a few Serial.print's. It could block for while if "conversionTime" is long..



  • How odd? Turned off and on... (which I'd tried obviously) and has worked perfectly since
    go figure



  • 700mm walls? Do you live in a blast shelter?! haha that has got to be infuriating. Although, the sound dampening from room to room between those walls has got to be nice!



  • It drives me crazy! The oldest part of the house pre-dates 1650 and was built to last. I have 4 wifi points hard-wired in as wifi will only reach the next room.

    On the plus side, it's cool in summer and warm in winter 😉


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 2
  • 1
  • 2
  • 1

15
Online

11.2k
Users

11.1k
Topics

112.5k
Posts