Quantcast
Viewing all articles
Browse latest Browse all 3285

Basic IoT scenario using HCP - Part 1 - Setup Particle Photon with sensors

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 Image may be NSFW.
Clik here to view.

 

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)

Image may be NSFW.
Clik here to view.
image004.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
Image may be NSFW.
Clik here to view.
image021.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

Image may be NSFW.
Clik here to view.
image022.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.

Image may be NSFW.
Clik here to view.
image023.jpg
Power-up your PhotonImage may be NSFW.
Clik here to view.
image025.png

Login into the particle cloud

 

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

Image may be NSFW.
Clik here to view.
image006.png
Select the “Code” option at the bottom left of the screen.Image may be NSFW.
Clik here to view.
image008.png
Create a new application by clicking on the “Create new app” button.Image may be NSFW.
Clik here to view.
Capture new app.JPG

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

Image may be NSFW.
Clik here to view.
image010.png
Your (empty) application is created and should like this.Image may be NSFW.
Clik here to view.
image012.png
Select the “Libraries” button on the bottom left.Image may be NSFW.
Clik here to view.
image014.png
Search for “dht” within the Community Libraries and select the “ADAFRUIT_DHT”.Image may be NSFW.
Clik here to view.
image016.png
Select the option “Include in APP”.Image may be NSFW.
Clik here to view.
image018.png
Select the APP you’ve just created. For instance the "Combined_00".Image may be NSFW.
Clik here to view.
image020.jpg
Select “Add to this APP”Image may be NSFW.
Clik here to view.
image021.png
The "ADAFRUIT_DHT” library should be included into your code now.Image may be NSFW.
Clik here to view.
image023.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.Image may be NSFW.
Clik here to view.
image026.png
When your code is successfully verified, you’ll get the following response at the bottom of the screen.Image may be NSFW.
Clik here to view.
image028.png
Publish your code to your Photon as it is successfully verified. Use the Flash button on the top left of the web ide.Image may be NSFW.
Clik here to view.
image031.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


Viewing all articles
Browse latest Browse all 3285

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>