Skip to Content

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. 😃

To report this post you need to login first.

14 Comments

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

  1. Iwona Hahn

    Can you please specify, that you are referring to the SAP Cloud Platform Internet of Things for the Neo environment? Thanks a lot!

     

    (0) 
    1. Nils Knieling Post author

      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.

      (0) 
  2. Trond Stroemme

    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.

    (0) 
  3. Lars Friedrich

     

    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.

    (0) 
    1. Anton Levin

      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

       

      (0) 

Leave a Reply