Skip to Content

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 🙂

Task Screenshot / 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)

/wp-content/uploads/2016/06/image004_971834.png

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
/wp-content/uploads/2016/06/image021_971828.jpg

– 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

/wp-content/uploads/2016/06/image022_971829.png

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

/wp-content/uploads/2016/06/image023_971830.jpg
Power-up your Photon /wp-content/uploads/2016/06/image025_972800.png

Login into the particle cloud

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

/wp-content/uploads/2016/06/image006_971777.png
Select the “Code” option at the bottom left of the screen. /wp-content/uploads/2016/06/image008_971779.png
Create a new application by clicking on the “Create new app” button. Capture new app.JPG

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

/wp-content/uploads/2016/06/image010_971799.png
Your (empty) application is created and should like this. /wp-content/uploads/2016/06/image012_971800.png
Select the “Libraries” button on the bottom left. /wp-content/uploads/2016/06/image014_971801.png
Search for “dht” within the Community Libraries and select the “ADAFRUIT_DHT”. /wp-content/uploads/2016/06/image016_971802.png
Select the option “Include in APP”. /wp-content/uploads/2016/06/image018_971803.png
Select the APP you’ve just created. For instance the “Combined_00”. /wp-content/uploads/2016/06/image020_971804.jpg
Select “Add to this APP” /wp-content/uploads/2016/06/image021_971805.png
The “ADAFRUIT_DHT” library should be included into your code now. /wp-content/uploads/2016/06/image023_971806.png
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. /wp-content/uploads/2016/06/image026_971819.png
When your code is successfully verified, you’ll get the following response at the bottom of the screen. /wp-content/uploads/2016/06/image028_971820.png
Publish your code to your Photon as it is successfully verified. Use the Flash button on the top left of the web ide. /wp-content/uploads/2016/06/image031_971821.png

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

To report this post you need to login first.

7 Comments

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

    1. Arnaut Kamhoot Post author

      Hi Kees,

      As suggested by Fadel, you can buy them directly from Particle or some resellers within the Netherlands. There are complete kits which include the breadboard and additionals.

      Regards,

      Arnaut.

      (0) 
    1. Arnaut Kamhoot Post author

      Hi Abhishek,

      I’m not sure if I understand your question correctly, but we have not been working on SDS related  to this blog.

      Regards,
      Arnaut.

      (0) 

Leave a Reply