- Posts: 46
- Karma: 1
- Thank you received: 7
Please Log in or Create an account to join the conversation.
VasilijHCN wrote: Its possible to create arduino+esp8266+ds18b20 temperature sensor node ?
Thank U for great job !!!
Please Log in or Create an account to join the conversation.
/*
V1.0 - first version
Created by Igor Jarc <igor.jarc1@gmail.com>
See http://iot-playground.com for details
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define CHILD_ID_TEMP 1
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Esp8266EasyIoT esp;
SoftwareSerial serialEsp(10, 11);
float lastTemp;
//Esp8266EasyIoTMsg msgHum(CHILD_ID_HUM, V_HUM);
Esp8266EasyIoTMsg msgTemp(CHILD_ID_TEMP, V_TEMP);
void setup()
{
serialEsp.begin(9600);
Serial.begin(115200);
sensors.begin();
Serial.println("EasyIoTEsp init");
esp.begin(NULL, 3, &serialEsp, &Serial);
//esp.begin(NULL, &serialEsp);
pinMode(13, OUTPUT);
// Serial.println("present S_TEMP");
esp.present(CHILD_ID_TEMP, S_TEMP);
}
void loop()
{
while(!esp.process());
delay(1000);
while(!esp.process());
sensors.requestTemperatures();
float temperature = (sensors.getTempCByIndex(0));
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DS18B20");
}
else if (temperature != lastTemp)
{
lastTemp = temperature;
esp.send(msgTemp.set(temperature, 1));
Serial.print("T: ");
Serial.println(temperature);
}
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.