Skip to content

Commit

Permalink
ESP8266 temp and hum sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
iot-playground committed Dec 18, 2014
1 parent 17a6618 commit e05725f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Esp8266EasyIoT/examples/clear_eeprom/clear_eeprom.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <EEPROM.h>

void setup()
{
for (int i=0;i<512;i++) {
EEPROM.write(i, 0xff);
}
}

void loop()
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
V1.0 - first version
Created by Igor Jarc <[email protected]>
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 <DHT.h>

#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 2


Esp8266EasyIoT esp;

SoftwareSerial serialEsp(10, 11);


DHT dht;
float lastTemp;
float lastHum;

Esp8266EasyIoTMsg msgHum(CHILD_ID_HUM, V_HUM);
Esp8266EasyIoTMsg msgTemp(CHILD_ID_TEMP, V_TEMP);


void setup()
{
serialEsp.begin(9600);
Serial.begin(115200);

Serial.println("EasyIoTEsp init");


esp.begin(NULL, 3, &serialEsp, &Serial);
//esp.begin(NULL, &serialEsp);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

pinMode(13, OUTPUT);

Serial.println("present S_HUM");
esp.present(CHILD_ID_HUM, S_HUM);

Serial.println("present S_TEMP");
esp.present(CHILD_ID_TEMP, S_TEMP);


mSetCommand(msgHum,C_SET);
// mSetCommand(msgTemp,C_SET);

mSetSender(msgHum,esp._nodeId);
// mSetSender(msgTemp,esp._nodeId);
}

void loop()
{
while(!esp.process());

delay(dht.getMinimumSamplingPeriod());

while(!esp.process());

float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
}
else if (temperature != lastTemp)
{
lastTemp = temperature;
esp.send(msgTemp.set(temperature, 1));
Serial.print("T: ");
Serial.println(temperature);
}

float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
}
else if (humidity != lastHum)
{
lastHum = humidity;
esp.send(msgHum.set(humidity, 1));
Serial.print("H: ");
Serial.println(humidity);
}
}




0 comments on commit e05725f

Please sign in to comment.