Iot | Controlling Any Device Using ESP8266 : Getting Started

by Start Bootstrap


Posted on Jul 21, 2019


The initial work for Home Automation

1. Admin Panel should able to set the device status on/off in the Table - Done

2. Expose Api which IoT Device will consume to set the device status - Done

From the examples given by Arduino, i can able to git the http server and here's the code to achieve it 

 

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "xxxx";
const char* password = "yyyy";

void setup () {

Serial.begin(115200);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

}

void loop() {

if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

HTTPClient http;  //Declare an object of class HTTPClient

http.begin("http://myinternalhttpserver.com/api/v1/ping");  //Specify request destination
int httpCode = http.GET();                                                                  //Send the request

if (httpCode > 0) { //Check the returning code

String payload = http.getString();   //Get the request response payload
Serial.println(payload);                     //Print the response payload

}

http.end();   //Close connection

}

delay(30000);    //Send a request every 30 seconds

}

 So, i can able to hit the http server and get the response in each interval. The next work will be establishing the same connection with https and to play with JSON

 

This is how admin area look like

 

 

 

 

 

Good day 💖


Search
Side Widget
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!