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
0 Kudos

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 2 - Photon receiving data

Welcome to part 2. Within this blog we use a second Photon with a relayboard and a 8 x 8 matrix display. The temperature and humidity data that was received from the SAPUI5 app will be posted towards the matrix display using the Particle Cloud API. The light treshold on the app in part 4 will toggle the led "on" and "off".

You could combine the code from part 1 and 2 and put the scenario on one Photon. Another thing you cloud replace is the relayboard. Instead of using that, you could also use a led (onboard led D7 for instance).

TaskScreenshot / Code

During this exercise we'll use the following items:

  • Particle Photon on breadboard
  • USB cable
  • Some wires
  • 8 x 8 matrix display (max7219)
  • Relayboard

Setup the relayboard with its pins connected in the following way:

  • VCC connected to 3V3 on the Photon
  • GND connected to GND on the Photon
  • Channel connected to D0 on the Photon

Setup the matrix display with its pins connected in the following way:

  • VCC connected to 3V3 on the Photon
  • GND connected to GND on the Photon
  • DIN connected to A2 on the Photon
  • CS connected to A4 on the Photon
  • CLK connected to A3 on the Photon
Powerup your Photon

Login into the particle cloud

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

Select the “Code” option at the bottom left of

the screen and create a new app. Just like we did in part 1 of the serie.

Select the “Libraries” button on the bottom left and search for the "MAX7219"

Include the library into your newly created application.
Copy/Enter the following code to your application.

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

#include "LedControl-MAX7219-MAX7221/LedControl-MAX7219-MAX7221.h"

LedControl *led;

int led1 = D0; //or D7 if you don't use the relayboard

int phase = 0;

char message[64];

char custMessage[64];

int messageLength = 0;

int myUptime = 0;

uint8_t data = A2;

uint8_t load = A4;

uint8_t myclock = A3;

void setup() {

led = new LedControl(data,myclock,load,1); //DIN,CLK,CS,HowManyDisplays

led->shutdown(0,false); //Turn it on

led->setIntensity(0,1);

Spark.function("SetMessage", setMessage);

Spark.variable("Message", custMessage, STRING);

pinMode(led1, OUTPUT);

Particle.function("led",ledToggle);

digitalWrite(led1, LOW);   

}

void loop() {

if(phase==0){ //Message-loop starts

        if(strlen(custMessage) == 0)

        {

            myUptime = (int)(millis()/1000);

            sprintf(message,"#SAPInsideTrack"); //update message

        }

        else

        {

            strcpy(message, custMessage); //update message

        }

        messageLength = strlen(message); // ...and length

        led->tweenLetters(0,' ',message[phase]); //scroll from empty to 1 letter

}

if(phase<messageLength-1){ //next characters except last one

led->tweenLetters(0,message[phase],message[phase+1]);

        phase++;

}else if(phase==messageLength-1){//last character scrolls to empty

        led->tweenLetters(0,message[phase],' ');

        phase = 0; //restart message-loop

}

}

int setMessage(String _message)

{

_message.toCharArray(custMessage, 64);

return 0;

}

int ledToggle(String command) {

if (command=="on") {

        digitalWrite(led1,HIGH);

        return 1;

}

else if (command=="off") {

        digitalWrite(led1,LOW);

        return 0;

}

else {

        return -1;

}

  }
Verify and Flash your code to the photon.
The Photon is now setup to receive the data from the SAPUI5 app through the Particle Cloud API. Continue to Part 3 and setup the Webhook and monitor the data which is being pushed from first Photon towards the HCP IoT Services.
Labels in this area