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).
Task | Screenshot / Code |
---|---|
During this exercise we'll use the following items:
| Image may be NSFW. Clik here to view. ![]() |
Setup the relayboard with its pins connected in the following way:
| Image may be NSFW. Clik here to view. ![]() |
Setup the matrix display with its pins connected in the following way:
| Image may be NSFW. Clik here to view. ![]() |
Powerup your Photon | Image may be NSFW. Clik here to view. ![]() |
Login into the particle cloud Go to: http://build.particle.io | Image may be NSFW. Clik here to view. ![]() |
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. | Image may be NSFW. Clik here to view. ![]() |
Select the “Libraries” button on the bottom left and search for the "MAX7219" | Image may be NSFW. Clik here to view. ![]() |
Include the library into your newly created application. | Image may be NSFW. Clik here to view. ![]() |
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. | Image may be NSFW. Clik here to view. ![]() |
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. |