In this page you will see how to build your first IoT device using Miniservice by BVRobotics infrastructure. This device constantly save the temperature using the meteo service available on the internet
If you need additional specific information about this topic or if you want to look it personally please write an email
#include "ESP8266WebServer.h"
#include "ESP8266WiFi.h"
#include "dht11.h"
#include "ESP8266HTTPClient.h"
The first version of the IoT firmware can be very basic (If you do not want to use the pre-defined firmware available in the Miniservice platform). I, personally, decided to not use any Oled Display to show the connection status. I simply used two leds a white one and a red one.
Start and retrieve the APN information stored into the EPROM of the NodeMCU
Try to connect to the APN
IF YES then activate the white led and start sending information every five minutes to the Miniservice temperature service
Activate a web server and if requested display the same temperature you read
IF NO then activate the RED led and start your APN (became an access point)
Open a web server and wait for a connection
Once a connection has been estabilished then ask for a new APN and a new password and store these info into the eprom
reset the board and start from scratch
The connections look like in the following picture:
bool testWifi(void) {
int c = 0;
WiFi.begin(esid.c_str(), epass.c_str());
Serial.println("Waiting for Wifi to connect");
while ( c < 20 ) {
if (WiFi.status() == WL_CONNECTED) { return true; }
delay(500);
Serial.print(WiFi.status());
c++;
}
Serial.println("");
Serial.println("Connect timed out, opening AP");
return false;
}
Here the function you can use to send to the temperature Miniservice an auth request to receive a token used to store the temperature:
String BuonevacanzeAuthenticate() {
String SendString, payload, StrToken;
HTTPClient http;
SendString = "http://www.buonevacanze.org/approver/default.aspx?PCC=" + ObjectCode + "&&APP=" + SVCTemperature + "&&TAG=0&&LANIP=" + WiFi.localIP().toString();
Serial.println("Sending = "+ SendString);
//Send Data to Buonevacanze
http.begin(SendString); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
payload = http.getString(); //Get the request response payload
StrToken = xmlTakeParam(payload,"Message");
Serial.println("HashCode: " + StrToken);
}
else
payload = "Not Authorized";
http.end(); //Close connection
return payload;
}
Read the temperature from the sensor is very easy:
dht11 DHT;
TempValue = DHT.read(DHT_PIN);
SendMeteoValues(Token,DHT.temperature,DHT.humidity);
Obviously SendMeteoValues Is the function I built to call the Temperature service once you have a valid token to use in this service categhory.
void SendMeteoValues(String Token,int Temp,int Hum)
{
String SendString, payload, StrToken;
HTTPClient http;
SendString = "http://www.buonevacanze.org/approver/temperature.aspx?TOKEN=" + Token + "&&TEMP=" + String(Temp) + "&&HUM=" + String(Hum) + "&&GEO=0";
Serial.println("Sending = "+ SendString);
//Send Data to Buonevacanze
http.begin(SendString); //Specify request destination
int httpCode = http.GET();
if (httpCode > 0) { //Check the returning code
payload = http.getString(); //Get the request response payload
StrToken = xmlTakeParam(payload,"ReturnMessage");
Serial.println("Result: " + StrToken);
}
http.end(); //Close connection
}
As described in the pages dedicated to Miniservices by bvrobotics.com, once those information have been stored you will have available also different services to manipulate them or to simply retrieve data stored in the central DB.