- Tue Apr 05, 2016 7:44 am
#44861
Good Day
I thought this will help to help me.
I need similer coding for arduino + ESP-05 (wifi) instead of Ethernet:
---------------------------------------------------------------------------------
#include <DHT.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define DHTTYPE DHT22
#define DHTPIN 2
String datain;
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
char datain_buff[8];
IPAddress ip(192, 168, 20, 164);
IPAddress server(192, 168, 20, 15);
EthernetClient ethClient;
DHT dht(DHTPIN, DHT22);
PubSubClient client(ethClient);
void reconnect() {
while (!client.connected()) {
if (client.connect("EnviroClient")) {
} else {
delay(5000);
}
}
}
void setup()
{
client.setServer(server, 1883);
Ethernet.begin(mac, ip);
delay(1500);
}
void loop()
{
if (!client.connected()) {
reconnect();
}
datain = String(dht.readTemperature());
datain.toCharArray(datain_buff, sizeof(datain_buff));
client.publish("enviro/192.168.20.164/temperatureC", datain_buff);
datain = String(Fahrenheit(dht.readTemperature()));
datain.toCharArray(datain_buff, sizeof(datain_buff));
client.publish("enviro/192.168.20.164/temperatureF", datain_buff);
datain = String(Kelvin(dht.readTemperature()));
datain.toCharArray(datain_buff, sizeof(datain_buff));
client.publish("enviro/192.168.20.164/temperatureK", datain_buff);
datain = String(dht.readHumidity());
datain.toCharArray(datain_buff, sizeof(datain_buff));
client.publish("enviro/192.168.20.164/humidity", datain_buff);
datain = String(dewPoint(dht.readTemperature(), dht.readHumidity()));
datain.toCharArray(datain_buff, sizeof(datain_buff));
client.publish("enviro/192.168.20.164/dewpoint", datain_buff);
client.loop();
delay(30000);
}
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
double Kelvin(double celsius)
{
return celsius + 273.15;
}
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078);
return (241.88 * T) / (17.558-T);
}
-------------------------------------------------------------------------------------------------------
Hope Someone can help.
Thank You
Albertus Geyser