Two Wire Temperature Sensor Convert from older gateway NEED HELP



  • Hi Everyone,

    I am using this old sketch for a two wire temp probe and upgraded to the 2.1.1 gateway and can't figure out what to change to get it to work. Do anyone know of a basic guide? I can't find one.

    #include <MySensor.h>
    #include <SPI.h>

    #define THERMISTORPIN A0
    #define THERMISTORNOMINAL 10000
    #define TEMPERATURENOMINAL 25
    #define NUMSAMPLES 5
    #define BCOEFFICIENT 3950
    #define SERIESRESISTOR 10000

    const unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    MySensor gw;

    // Initialize temperature message
    MyMessage msg(0,V_TEMP);

    int samples[NUMSAMPLES];

    void setup(void) {

    pinMode(THERMISTORPIN, INPUT);
    analogReference(EXTERNAL);

    // Startup and initialize MySensors library. Set callback for incoming messages.
    gw.begin();

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Temperature Sensor", "1.1");

    // Present all sensors to controller
    gw.present(0, S_TEMP);
    }

    void loop(void) {
    // Process incoming messages (like config from server)
    gw.process();

    float average;

    // take N samples in a row, with a slight delay
    for (uint8_t i=0; i< NUMSAMPLES; i++) {
    samples[i] = analogRead(THERMISTORPIN);
    delay(10);
    }
    // average all the samples out
    average = 0;
    for (uint8_t i=0; i< NUMSAMPLES; i++) {
    average += samples[i];
    }
    average /= NUMSAMPLES;

    Serial.print("Average analog reading ");
    Serial.println(average);

    // convert the value to resistance
    average = 1023 / average - 1;
    average = SERIESRESISTOR / average;
    Serial.print("Thermistor resistance ");
    Serial.println(average);

    float temperature;
    temperature = average / THERMISTORNOMINAL; // (R/Ro)
    temperature = log(temperature); // ln(R/Ro)
    temperature /= BCOEFFICIENT; // 1/B * ln(R/Ro)
    temperature += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
    temperature = 1.0 / temperature; // Invert
    temperature -= 258.95; // convert to C

    Serial.print("Temperature ");
    Serial.print(temperature);
    Serial.println(" *C");
    // Send in the new temperature
    gw.send(msg.setSensor(0).set(temperature,1));
    // delay(1000);
    gw.sleep(SLEEP_TIME);
    }


  • Hardware Contributor

    Hello,

    you need to convert your node to MySensors 2.x api. you can see how it looks in MySensors examples and there are also some guidelines here: https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x



  • Hi

    Thank you for the prompt reply, I will have a look.

    Thanks
    T


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.