Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Cyclenerd
Explorer
6,430
In this article I will briefly explain how you can build your own weather station and connect it to the  SAP Cloud Platform Internet of Things in the Neo environment.

It is a good example to familiarize yourself with SAP Cloud.

This article is based in part on the Starter Kit for the SAP Cloud Platform Internet of Things.

Based on this article, I'll publish more. In the next article, we will program a SAPUI5 application to process the sensor data (UPDATE: 2017/09/02 - Next article is online).

 

Requirements


You need:

  • One ESP8266 - NodeMCU

    • I use the NodeMCU Lua Lolin V3 Module



  • One DHT22 sensor

  • Three LEDs

  • A few cables and a Breadboard to connect everything


 

Get SAP Cloud Platform Developer Account


In addition, you need an account in the SAP Cloud. The trial is free. So just sign up: https://cloudplatform.sap.com/

 

Enable Internet of Things


Before you can use SAP Cloud Platform Internet of Things you have to enable it in your SAP Cloud Platform Cockpit.

In your SAP Cloud Platform Cockpit navigate to "Services" section and click on "Internet of Things" tile.



Press "Enable" button.



You are now ready for the next step and may already click on "Go to Service" link for that.

 

Create Device Information in Internet of Things Cockpit


The following description of interaction steps with the Internet of Things Cockpit shows you how to create a Device Type and Message Types associated with it as well as a Device instance.



 

Message Types


Press on Message Types tile in your Internet of Things Cockpit.

Press on the + button to add a new message type.



Create the following specific Message Type. In this format the weather data will be transmitted later.

Fields:

  • celcius : double

  • fahrenheit : double

  • humidity : double


Important: Make a note of the Message ID. We need that later.



 

Create Device Type


Press on Device Types tile in your Internet of Things Cockpit.

Press on the + button to add a new device type.

Fields:

  • Enter the Name "Weather Stations"

  • Select the message type you just created

  • Choose the message direction "From Device"


 



 

Create Device


Press on Devices tile in your Internet of Things Cockpit.

Press on the + button to add a new device.

Fields:

  • Enter a Name for the new weather station

  • Select the device type you just created


 



Important: Make a note of the Device ID. We need that later.

 

Deploy the Message Management Service (MMS)


The deployment of the Message Management Service (MMS) step needs to be done from the "Deploy Message Management Service" tile in the Internet of Things Cockpit and deploys/starts the Message Management Service that takes care of receiving data from IoT Devices and sending to these.



Then assign the Role IoT-MMS-User for the newly deployed iotmms Java Application (otherwise you will be denied access to the iotmms Application URL with an HTTP Status 403 Error). To do so:

  • Go to the Java Applications tab in your SAP Cloud Platform Cockpit of your account

  • Choose the iotmms application

  • Choose the Security tab of the Application details and then select Roles




Do the assignment of the role to your user.



Once MMS is deployed and you have correctly done role assignment you can click on the iotmms Java application URL in your SAP Cloud Platform Cockpit and get to the MMS Cockpit as shown below. It provides access to the MMS API as well as a "Display stored messages" tile for the access to data received from IoT Devices.



 

Configure the Message Management Service


Our weather station will later publish its data via MQTT. We use the public and free MQTT broker iot.eclipse.org.

In order for the data to be stored in the SAP Cloud, we must also connect the MMS service to the MQTT broker.

Click on "Configuration" tile:

  • Enter the MQTT Broker Endpoint: tcp://iot.eclipse.org:1883

  • Enable the MQTT Connection !!!

  • Enter the Password: sapcloud

  • Enter the User Name: sapcloud




 

Test Connection


Click on "MQTT TCP/SSL API" tile.

Enter the Device ID and click Connect. Write down the MQTT topic. We'll need it later.



 

Now everything is set up in the SAP Cloud. We can now take care of our weather station.

 

Set-Up


The programming is done with the Arduino IDE. If you do not have it yet, install it.

Add in Preferences the "Additional Boards Manager URL": http://arduino.esp8266.com/stable/package_esp8266com_index.json



Select the right board:



 

Libraries


Install the required libraries. Search for:

  • DHT

  • ESP8266WiFi

  • PubSubClient

  • ArduinoJson

  • Adafruit Unified Sensor Driver




 

? Increase the MQTT library's memory limit ?


Open the PubSubClient.h file from the Arduino libraries folder. Increasing MQTT_MAX_PACKET_SIZE to 256.

On a Mac, this will be located at: ~/Documents/Arduino/libraries/PubSubClient/src/PubSubClient.h

Wiring


 



 

Connect the DHT22 data pin to D6.
  _______
/ ( ) \
+-------+
| [] [] |
| [] [] |
| [] [] |
+-------+
| | | |

\ \ \ \__ Ground: Connect it to GND
\ \ \___ Nothing
\ \____ Data pin: Connect it to D6
\_____ Positive pin: Connect it to 3v3

Connect D0, D1, D2 each with one LED.

 

Program


You can find the finished program for your weather station in my GitHub repository: https://github.com/Cyclenerd/iot-weather-mqtt

Download and open iot-weather-mqtt.ino with the Arduino IDE and adjust the configuration:

  • ssid : Your WiFi SSID

  • password : Your WiFi password

  • sap_iot_msg_id : The message ID you wrote down in the previous steps

  • mqtt_topic : The MQTT topic you wrote down in the previous steps


 

Upload iot-weather-mqtt.ino to your ESP8266.

When everything is working, all LEDs light up:

  • D0 : Power on

  • D1 : WiFi connected

  • D2 : MQTT connected


Messages should appear on the MQTT topic. Here's an example:
{
"mode":"async",
"messageType":"bd03144608253c6a4fca",
"messages":[
{"celcius":23.4,"fahrenheit":74.12,"humidity":67.59999}
]
}

 

Finished.

 

When everything is working, the sensor data are now stored in your Message Management Service Cockpit under Application Data.






I hope you enjoy discovering SAP Cloud. ?
20 Comments
moyalynne
Active Contributor
0 Kudos
This is awesome!  Can't wait to give it a try!  Sensors, Adafruit, everything!
iwona_hahn
Product and Topic Expert
Product and Topic Expert
0 Kudos
Can you please specify, that you are referring to the SAP Cloud Platform Internet of Things for the Neo environment? Thanks a lot!

 
Cyclenerd
Explorer
0 Kudos
Hi,

We use here SAP Cloud Platform Internet of Things in the Neo environment. I added that in the introduction. In the CF Trial there is currently no IoT.
MTNguyen
Participant
0 Kudos
How is the setup of Add in Preferences the “Additional Boards Manager URL”: can be done in windows actually?

 
Cyclenerd
Explorer
Vitaliy-R
Developer Advocate
Developer Advocate
0 Kudos
Hi Nils. Thanks for sharing this!

You might want to import this project intro https://www.hackster.io/sap/products/sap-cloud-platform-iot-for-the-neo-environment to reach out to more NodeMCU enthusiasts.

Best regards.
Former Member
0 Kudos
I find the IoT platform a bit of an overkill for this kind of scenario. Easier then to just set up a table on the SAP-CP with the desired format, and just do simple service calls to add records. In addition, with such a simplified solution, it is easier to consume the resulting data in, say, a Fiori or UI5 app - as opposed to building an app based on the IoT data tables.

Another drawback is that if you have specific IoT devices that sends messages in very specific pre-determined formats (such as the Cloudbit from Littlebits), you may need to use webhooks or other services to re-format the JSON payload into the format expected by the IoT service on SAP-CP. This is especially true for some of the "out-of-the-box" devices only working with IFTTT, where no "massaging" or re-programming of the device itself is possible.

A good introduction to the platform itself, though.
former_member297227
Discoverer
0 Kudos
 

Hi Nils, thanks for this nice example!

When I follow your instructions and then try to test the MQTT TCP connection the Button"Connect" is greyed out and disabled. Do you have any clue what could be the reason?

Thank you and best regards.
anton_levin
Product and Topic Expert
Product and Topic Expert
0 Kudos
You would need to configure your endpoint and enable MQTT connection in MMS Configs. See some screenshots in the IoT StarterKit https://github.com/SAP/iot-starterkit/tree/master/neo/apps/built-in/sending/mqtttcp

 
Cyclenerd
Explorer
0 Kudos
Exactly. There or in this article under the heading "Configuring the Message Management Service"
Cyclenerd
Explorer
Cyclenerd
Explorer
Former Member
0 Kudos
hello nils,

I made the configuration as described. but my button is also gray and i can not make a connection test.

regards, marcel
Cyclenerd
Explorer
0 Kudos
Hi Marcel,

Check the settings and make sure you have activated MQTT.

 
Flavio
Active Contributor
0 Kudos
Thank you Nils for sharing this very interesting IoT project.

Just tried it out and it perfectly works. Now looking at the next step...

 

0 Kudos
Hi Nils. Thanks for the sharing!

I tried to connect the MQTT service "iot.eclipse.org" with port 1883, but client.connected() return 0,

I tested connection in SAP Cloud Platform, and it worked fine, but not for Arduino

do you have any idea about this?

 

 

 
Former Member
0 Kudos
Hi Nils

when the real data gets acquired, we get error message......






{"code":400,"msg":"Parse error. Expected [messageType] of type [string]"}

 
former_member600292
Discoverer
0 Kudos
I'm glad to see that Sap is also serving the cloud management of the Internet of Things. I am in China. There are several big cloud data service providers in China, such as China Mobile, Huawei, Alibaba, etc. IBM is also developing the Internet of Things cloud system.

I think this should be the trend in the future. I am engaged in the production of meteorological equipment. Before, equipment data were stored locally or deployed localized systems. But with the increasing amount of data or the replacement of servers, the previous data "disappeared", but if there is SaaS system, I think it will be much better. As a manufacturer or user, we only need to pay attention to the use of data, without paying attention to it. There's a problem with deployment.

I hope to have more in-depth communication with Sap. The following is an introduction to the application of weather stations, which I believe you will be interested in.

Https://www.weatherstation1.com/
mishra_mayank
Explorer
0 Kudos
I am also facing the same issue. Did you find the solution?

thanks in advance!

Regards Vignesh K.
bernd_broesamle
Advisor
Advisor
0 Kudos
It took me a while to figure out that one step is missing in this description after entering the device ID using tile “MQTT TCP/SSL API” and noting down the MQTT topic.

After clicking "Connect" you need to once send a message (below section "Publish Message"):
{"mode":"async","messageType":"<message type ID>","messages":[{"celsius":37.0,"fahrenheit":100.0,"humidity":99.9}]}

Below "Reply from Server" there should be a message like:

{"code":202,"msg":"1 message(s) received from device [<Device ID>]"}

By this, the corresponding table for storing the Application Data (T_IOT_<message type ID>) will be generated.

After that, you will find this new table when you click the tile "Display stored messages".

Thanks for this great tutorial.
Labels in this area