Skip to Content

Hello people,

Here is a small and simple IOT project that I did to test ESP8266 node Mcu connecting to  SAP Cloud Platform Internet of Things environment.

For this small project i have used :

  1.  ESP8266-12 Node MCU
  2.  Protoboard
  3.  Pulse sensor

 

For the ESP8266 coding, I am using Arduino IDE. If you don’t have Arduino IDE you can download it from http://www.arduino.cc

I have setup the ESP8266 board in the Arduino IDE opening it and configuring the ESP8266 in the  :

File –>Preferences –> additional boards Managers URLs. In this field, fill it with the following URL:   http://arduino.esp8266.com/stable/package_esp8266com_index.json.

Before start your codification, you will need to specify the board Generic ESP8266 in the Board Manager in the Arduino IDE ( Menu : Toos–> Board –> Generic ESP8266).

After that, connect the ESP8266 with a power source with 3,3 V. If don’t have a power source with this voltage you can use a voltage regulator or divide the voltage using resistor. The last option works but is not recommended. ESP8266 is very sensible about voltage and any voltage variance could damage your board.

Connect the pulse sensor with the analog port in the ESP8266.

At the end, your circuit should appear with that :

 

For the next step, you will need to create an account in https://account.hanatrial.ondemand.com.

On the Hana Cloud cockpit, look for Internet of things and enable the service.

In the Internet of Things Service Cockpit, you need to create  Device, Message type and Device Type.

Device – it will be your ESP8266 board. You will use the Device ID generated by the system in your code. In the device configuration, you can generate a token to use id to authenticate in the SAP Cloud Platform Internet of Things.

Message Type – it will be the message with the data that you will collect from the sensors connected to the ESP8266. In this Project, the data will be the time Stamp and the heart frequency read from the Pulse Sensor. The system will generate a message type id. This information will be used in th

Device Type – it is the link between the device Id and Message Type Id created above.

Here is an example of the code : 

//

….. initial configuration for Wifi client (look for wifi connection in the Arduino IDE examples)

 

//   Initial variants and constants:

// SAP Cloud Platform specific configuration
const char* host = “iotmmsXXXXXXXtrial.hanatrial.ondemand.com”;
String device_id = “XXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX”;
String message_type_id = “XXXXXXXXXXXXXX”;
String oauth_token=”XXXXXXXXXXXXXXXXXXXXXXXXXX”;

// Below, I am using HTTP with Post method to send data to SAP Cloud Platform:

// just an example payload corresponding to the other Starterkit examples
String post_payload = “{\”mode\”:\”async\”, \”messageType\”:\”” + message_type_id + “\”, \”messages\”:[{ \”timestamp\”:1413191650, \”pulse\”:”+Signal+”, \”value\”:\”20\”}]}”;

const int httpsPort = 443; //HTTP port
WiFiClientSecure client;

 

// The SetUp Function:
void setup() {

// SAP Cloud Platform _ trying to connect the SAP Cloud – Use WiFiClientSecure class to create TLS          connection

Serial.print(“connecting to “);
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println(“connection failed”);
return;
}

// using HTTP/1.0 enforces a non-chunked response

client.print(String(“POST “) + url + ” HTTP/1.0\r\n” +
“Host: ” + host + “\r\n” +
“Content-Type: application/json;charset=utf-8\r\n” +
“Authorization: Bearer ” + oauth_token + “\r\n” +
“Content-Length: ” + post_payload.length() + “\r\n\r\n” +
post_payload + “\r\n\r\n”);

Serial.println(“request sent”);

Serial.println(“reply was:”);
Serial.println(“==========”);

while (client.connected()) {
String line = client.readStringUntil(‘\n’);
Serial.println(line);
}

Serial.println(“==========”);
Serial.println(“closing connection”);

}

 

One time the code is compiled and loaded into ESP8266 and the board is connected to power source, if you put your finger in the sensor, you will get to see the data loaded in the SAP Cloud Platform :

 

 

Summarizing :  ESP8266 module is perfect solution to connect any IOT project to SAP Cloud Platform, but it depends of what you want to do.

If you want only to collect data from a remote sensor, it could be a cheaper and good solution. But if you want put some logic or control multiple sensors at the same type, Raspberry PI could be a better approach.

Some advantages about ESP8266:

  • Cheaper solution for IOT
  • Small size allowing to create small devices, very helpful in wearables projects
  • Wifi embedded

But it have some disadvantages too:

  • It not support voltage variance. Any voltage different of 3,3 V could damage the module
  • depending of the circuit that you are building, some voltage regulator could be necessary, bringing more complexity to your project
  • like arduino, ESP8266 is a micro-controller. It not support multiple threads. Different than Raspberry PI that is a micro-processor

Thank you All.

William Terceiro

 

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply