tonyn79 wrote: EasyIoT
I've just tested ESP Arduino and created relay example with EasyIoT server. It's very easy to program ESP.
Any chance you could post code for that?
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.
/*
* This sketch sends data via HTTP POST request to easyIoT server.
*/
#include <ESP8266WiFi.h>
#include <Base64.h>
//WIFI credentials go here
const char* ssid = "MYSSID";
const char* password = "myP@ssW0rd";
//easyIoT credentials go here
char uname[] = "admin:test"; //needs to be replaced with your user/pass
char unameenc[40];
const char* host = "192.168.1.23"; //replace this with your easyIoT server IP address
const int httpPort = 81; //custom easyIoT server http port
const char* nodeID = "N7S0"; //node ID of corresponding virtual node
void setup() {
Serial.begin(115200);
delay(10);
//generate base64 string from credentials, for http basic auth
memset(unameenc,0,sizeof(unameenc));
base64_encode(unameenc, uname, strlen(uname));
// We start by connecting to a WiFi network
Serial.println();
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("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "";
url += "/Api/EasyIoT/Control/Module/Virtual/";
url += nodeID;
//url += "/ControlOn"; //use this for simple switch, i.e. DigitalOutput virtual node type
url += "/ControlLevel/"; // use this for things with more possible values then just one and zero
url += value;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"Authorization: Basic " + unameenc + " \r\n" +
"Content-Length: 0\r\n" +
"\r\n"
);
delay(10);
// 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);
}
Serial.println();
Serial.println("closing connection");
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Dennis wrote: Another one, this time reading a DS18B20 1-wire sensor on GPIO2 every ten seconds, and updating a virtual node of type "Temperature output (AO)" with its data EDIT - just created a github repo, here it is:
github.com/DennisSc/easyIoT-ESPduino/blo...sketches/ds18b20.ino
regards
Please Log in or Create an account to join the conversation.