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 10000const 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 CSerial.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);
} -
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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login