- Posts: 11
- Thank you received: 1
// Serial.println("present S_HUM");
esp.present(CHILD_ID_HUM, S_HUM);
// Serial.println("present S_TEMP");
esp.present(CHILD_ID_TEMP, S_TEMP);
esp.present(1, S_DIGITAL_OUTPUT);
esp.present(2, S_DIGITAL_OUTPUT);
esp.present(3, S_DIGITAL_OUTPUT);
esp.present(4, S_DIGITAL_OUTPUT);
/*
V2.0 - small fix
Created by Igor Jarc <admin@iot-playground.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 <DHT.h>
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 2
#define SEND_INTERVAL 1000 * 30 // 30S
#define RELAY_1 6 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
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);
unsigned long startTime;
void setup()
{
serialEsp.begin(9600);
Serial.begin(115200);
Serial.println("EasyIoTEsp init");
//esp.begin(NULL, 3, &serialEsp, &Serial);
esp.begin(incomingMessage, 3, &serialEsp, &Serial);
//esp.begin(NULL, &serialEsp);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
pinMode(13, OUTPUT);
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_1 + 1, OUTPUT);
pinMode(RELAY_1 + 2, OUTPUT);
pinMode(RELAY_1 + 3, 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);
esp.present(1, S_DIGITAL_OUTPUT);
esp.present(2, S_DIGITAL_OUTPUT);
esp.present(3, S_DIGITAL_OUTPUT);
esp.present(4, S_DIGITAL_OUTPUT);
startTime = millis()+SEND_INTERVAL;
}
void loop()
{
esp.process();
while(!esp.process());
if (IsTimeout())
{
startTime = millis();
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);
}
while(!esp.process());
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);
}
}
}
boolean IsTimeout()
{
unsigned long now = millis();
if (startTime <= now)
{
if ( (unsigned long)(now - startTime ) < SEND_INTERVAL )
return false;
}
else
{
if ( (unsigned long)(startTime - now) < SEND_INTERVAL )
return false;
}
return true;
}
// below from 4 relays
void incomingMessage(const Esp8266EasyIoTMsg &message) {
// We only expect one type of message from controller. But we better check anyway.
Serial.println("New message");
if (message.type==V_DIGITAL_VALUE) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Sunspot wrote: I assume the node details found by the automatic scan are stored in the Pi somewhere?
(then perhaps I can tweak the data to add the missing relays?)
I am looking with ftp as root but can't see where the nodes are stored.
(I cant even see the index.html - usually in /var/www/???)
I would love to understand the web page creation process!
Is there any documentation?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.