Create your own Weather Station with SAP Cloud Platform Internet of Things
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
- I use the
- 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 SSIDpassword
: Your WiFi passwordsap_iot_msg_id
: The message ID you wrote down in the previous stepsmqtt_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 onD1
: WiFi connectedD2
: 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. ?
This is awesome! Can't wait to give it a try! Sensors, Adafruit, everything!
Can you please specify, that you are referring to the SAP Cloud Platform Internet of Things for the Neo environment? Thanks a lot!
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.
How is the setup of Add in Preferences the “Additional Boards Manager URL”: can be done in windows actually?
https://learn.adafruit.com/add-boards-arduino-v164/setup
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.
Thanks for the hint 🙂 https://www.hackster.io/Cyclenerd/weather-station-with-sap-cloud-platform-internet-of-things-2b1d56
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.
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.
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
Exactly. There or in this article under the heading "Configuring the Message Management Service"
hello nils,
I made the configuration as described. but my button is also gray and i can not make a connection test.
regards, marcel
Hi Marcel,
Check the settings and make sure you have activated MQTT.
Next article (part 2) is online: https://blogs.sap.com/2017/09/02/sapui5-app-for-the-built-in-mms-odata-api-from-the-sap-cloud-iot-for-your-weather-station/
Have fun 🙂
Thank you Nils for sharing this very interesting IoT project.
Just tried it out and it perfectly works. Now looking at the next step...
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?
Hi Nils
when the real data gets acquired, we get error message......
I am also facing the same issue. Did you find the solution?
thanks in advance!
Regards Vignesh K.
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/
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"):
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.