ESP8266 Arduino IDE is OUT !!!

9 years 2 weeks ago #1050 by EasyIoT

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?


Yes, this is ESP code
github.com/iot-playground/Arduino/blob/m...er/WiFiWebServer.ino

and automation part is little moddified code from this thread:
iot-playground.com/forum/suggestion-box/...-only-needed?start=6

Next week I will prepare tutorial.

Please Log in or Create an account to join the conversation.

9 years 1 week ago #1051 by VasilijHCN
in automation part need to send /gpio/0 or /gpio/1 for On/Off ?

Please Log in or Create an account to join the conversation.

9 years 1 week ago - 9 years 1 week ago #1066 by Dennis
Yes, send http GET request "/gpio/0" will turn it off.

For example,

sendToServer("GET /gpio/" + p.value + " HTTP/1.1");

regards
The following user(s) said Thank You: VasilijHCN

Please Log in or Create an account to join the conversation.

9 years 1 week ago #1069 by Dennis
I've played around with easyIOT HTTP API and new shiny Arduino IDE for esp8266, and here's some result - I can update a virtual node directly from esp8266...

(note that it uses base64 library from here to encode credentials: github.com/adamvr/arduino-base64 )
/*
 *  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");
}


But I noticed that I can only update actor like things via HTTP API (in fact only found working "ControlOff" for digital output node type, and "ControlLevel/[value]" for dimmer node type to work), there seems to be no API for temperature sensor, or analog input? Can we get a list of possible HTTP API requests maybe?, pretty pleeeease?

regards

Please Log in or Create an account to join the conversation.

9 years 1 week ago - 9 years 1 week ago #1071 by Dennis
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.

9 years 1 week ago #1073 by EasyIoT

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


Thank you for all this code examples. I will prepare tutorials in the future.
Regarding EasyIoT REST API - in next release I will add API interface for AI inputs. That way it will be possible to set for example temperature on AI temperature node.
The following user(s) said Thank You: Dennis

Please Log in or Create an account to join the conversation.

Time to create page: 0.235 seconds

Forum latest

  • No posts to display.