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: 
Former Member

This blog is part of a series which is related to a end-to-end IoT scenario. This is the full scenario used for the mini CodeJam that was organised at the SAP Inside Track 2016 Belgium #sitBRU.

Basic IoT scenario using HCP and Particles and UI5 - the explanation

Part 1 - Photon sending data

Welcome to part 1. In this blog we'll create the first Particle Photon for sending the data towards the HCP IoT Services. In my previous blog about the Particle Photon I promised an extended version of the Photon with a so called DHT11 sensor for measuring humidity and temperature. Well here it is...and a bit more :smile:

TaskScreenshot / Code

By now there should be more than enough information on SCN about how to enable and setup the IoT services on HCP. A brief description about the device and fields should be sufficient to get you going. 

During the exercise you will need one device, with one messagetype. Use the fields from the picture on the right (case sensitive)

During this exercise we'll use the following items:

  • Particle Photon on breadboard
  • DHT11
  • USB cable
  • some wires
  • 220 ohm resistor
  • 1k ohm resistor
  • photo resistor

- Setup the photo resistor with its pins connected to A5 and A0.

- Setup the 220 ohm resistor with its pins connected to GND (ground) and A0

- Setup the DHT11 sensor with its pins connected to rows 17, 18 and 19. Be sure to check that “+” is connected to 19.

- Setup the 1K ohm resistor with its pins connected to Row 18 and the “+” row on the breadboard.

- Connect the green wire between row 18 and pin D3 on your Photon.

- Connect the yellow wire between row 17 and the “-” row.

- Connect the red wire between row 19 and the “+” row.

- Connect the dark grey wire between “-“ row and pin GND on the Photon.

- Connect the white wire between the “+” row and pin 3v3 on the Photon.

Power-up your Photon

Login into the particle cloud

Go to: http://build.particle.io

Select the “Code” option at the bottom left of the screen.
Create a new application by clicking on the “Create new app” button.

Enter the name of your application: "Combined_##" and press enter.

Your (empty) application is created and should like this.
Select the “Libraries” button on the bottom left.
Search for “dht” within the Community Libraries and select the “ADAFRUIT_DHT”.
Select the option “Include in APP”.
Select the APP you’ve just created. For instance the "Combined_00".
Select “Add to this APP”
The "ADAFRUIT_DHT” library should be included into your code now.
Copy/Enter the following code to your application.

// This #include statement was automatically added by the Particle IDE.

#include "Adafruit_DHT/Adafruit_DHT.h"

#define DHTPIN 3

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

int photoresistor = A0;

int power = A5;

char resultStr[260];

void setup() {

   

    Serial.begin(9600);

    dht.begin();

    pinMode(photoresistor,INPUT); 

    pinMode(power,OUTPUT);   

    digitalWrite(power,HIGH);

}

void loop() {

    float tempLight =  analogRead(photoresistor);

    float tempHum = dht.getHumidity();

    float tempTmp = dht.getTempCelcius();

   

    char *hcp_user = " YOUR SAP USER HERE";

    char *hcp_device = " YOUR HCP DEVICE ID HERE";

    char *hcp_bearer = " YOUR HCP BEARER CODE HERE";

    char *hcp_messageType = " YOUR HCP MESSAGE TYPE HERE";

   

    sprintf(resultStr, "{\"HCP_USER\": \"%s\", \"HCP_BEARER\": \"%s\", \"HCP_DEVICEID\": \"%s\", \"HCP_MTYPE\": \"%s\", \"LIGHT\": \"%f\", \"TEMP\": \"%f\", \"HUM\": \"%f\"}", hcp_user, hcp_bearer, hcp_device, hcp_messageType, tempLight, tempTmp, tempHum);

    Particle.publish("WebHook_00", resultStr, 60, PRIVATE);

    memset(resultStr, 0, 255);

    delay(30000);

  }

Add your details to the following variables:

  • hcp_user
  • hcp_device
  • hcp_bearer
  • hcp_messageType

    char *hcp_user = " YOUR SAP USER HERE";

    char *hcp_device = " YOUR HCP DEVICE ID HERE";

    char *hcp_bearer = " YOUR HCP BEARER CODE HERE";

    char *hcp_messageType = " YOUR HCP MESSAGE TYPE HERE";

Notice the name (WebHook_00) of the webhook that will be used during the publish event in your code. Rename it as you like, but be sure to use the same name when you create the webhook in the next blog (part 3 of the serie).    Particle.publish("WebHook_**", resultStr, 60, PRIVATE);
Verify your code with the button on the top left.
When your code is successfully verified, you’ll get the following response at the bottom of the screen.
Publish your code to your Photon as it is successfully verified. Use the Flash button on the top left of the web ide.

As soon as your code is flashed and the Photon is connected again, your code is active and being executed. Please be aware that the webhook is not in place yet. This will be done in part 3 of this blogserie.

The next step will be the setup of the Photon which will be receiving the data from the UI5 app. Part 2

7 Comments
Labels in this area