- Posts: 55
- Thank you received: 6
Dennis wrote: congrats.
You can set the Unit in the easyIot servers module settings..
regards
Please Log in or Create an account to join the conversation.
/*
Created by Igor Jarc
See http://iot-playground.com for details
Please use community fourum on website do not contact author directly
Code based on https://github.com/DennisSc/easyIoT-ESPduino/blob/master/sketches/ds18b20.ino
External libraries:
- https://github.com/adamvr/arduino-base64
- I forget where do i get this DHT Library (i think i got it from ESP8266 Arduino IDE)
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.
Add Temperature Node in EasyIoT Server (Driver - Virtual Driver)
Add Humidity Node in EasyIoT Server (Driver - Virtual Driver)
*/
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <Base64.h>
const char* ssid = "Your SSID";
const char* password = "Your Wifi Password";
const char* host = "IP Address of EasyIoT Server";
const char* nodet = "Your Node for temperature";
const char* nodeh = "Your Node for Humidity";
const char* user = "admin";
const char* userpassword = "test";
#define DHTPIN 2 // what pin we're connected to
DHT dht(DHTPIN, DHT11,15);
#define USER_PWD_LEN 40
char unameenc[USER_PWD_LEN];
void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
// Connect to WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
char uname[USER_PWD_LEN];
String str = String(user)+":"+String(userpassword);
str.toCharArray(uname, USER_PWD_LEN);
memset(unameenc,0,sizeof(unameenc));
base64_encode(unameenc, uname, strlen(uname));
}
void loop() {
Serial.print("Connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections for Humidity
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
float h = dht.readHumidity();
if (isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
String urlh = "";
urlh += "/Api/EasyIoT/Control/Module/Virtual/"+ String(nodeh) + "/ControlLevel/"+String(h); // generate EasIoT server node URL
Serial.print("POST data to URL: ");
Serial.println(urlh);
client.print(String("POST ") + urlh + " HTTP/1.1\r\n" +
"Host: " + String(host) + "\r\n" +
"Connection: close\r\n" +
"Authorization: Basic " + unameenc + " \r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(5000);
// Use WiFiClient class to create TCP connections for Temperature
WiFiClient client2;
const int httpPort1 = 80;
if (!client2.connect(host, httpPort1)) {
Serial.println("connection failed");
return;
}
float t = dht.readTemperature();
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
String urlt = "";
urlt += "/Api/EasyIoT/Control/Module/Virtual/"+ String(nodet) + "/ControlLevel/"+String(t); // generate EasIoT server node URL
Serial.print("POST data to URL: ");
Serial.println(urlt);
client2.print(String("POST ") + urlt + " HTTP/1.1\r\n" +
"Host: " + String(host) + "\r\n" +
"Connection: close\r\n" +
"Authorization: Basic " + unameenc + " \r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(100);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
while(client2.available()){
String line = client2.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
// Repeat every 5 minutes
delay(300000);
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
cdj wrote: I want to use this, we can eliminate automation, but the problem is: no float value? No 23.7 degree (for ex)
This is the reason of my calculation in automation, and in bmp you must make calculation to have a common value of pressure...
Pherhaps in this way i resolve my strange graph problems...
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.