Skip to Content
Author's profile photo Fabian Lehmann

Using SAP HCP, integration service to post a message to your Photon IoT device part 2

In Addition to the last post:

Using SAP HCP, integration service to post a message to your Photon IoT device part 1

I will show you In this blog how we can use some simple coding and SAP HCP, integration service to display the messge on the matrix modules.

Step 1: Connect the Photon via USB

Step 2: Write/adapt and flash your code

Enter the partice IDE: https://build.particle.io

Now write some lines….or use the nice Adafruit example.
For me it works fFine, i adapt/reduce something for my needs:

#include "Adafruit_GFX.h"
#include "ledmatrix-max7219-max7221.h"

boolean HCPblink = false;
boolean HCPMSG = false;
boolean MatrixHCPText =false;
LEDMatrix *led;
int counter = 0;
String text = "";
int textLength = 0;
// default position of the text is outside and then scrolls left
int textX = 8;
int fontWidth = 4, space = 2;

void setup()   {
     Serial.begin(9600);
    //Matrix
    led = new LEDMatrix(2, 1, A0, A1, A2);
    led->addMatrix(0, 0, 90, false, false);
    led->addMatrix(1, 0, 90, false, false);
    Particle.function("HCPWriteText",WriteText);
   
}

void loop() {
     if (MatrixHCPText) {
       if(led != NULL && counter < 4) {
    drawText(text, textX--);
    led->flush();
    delay(75);
  }
  else if (led != NULL) {
    led->shutdown(true);
    delete led;
    led = NULL;
  }
     }
    
}
// cloud function caled by HCP Integration Service
int WriteText(String msg) {
    textLength = msg.length();
    if(msg.length() > 0){
    text = msg;
        MatrixHCPText = true;
     return 0;
    }
    else {
        return -1;
    }
    
}
// draw text
void drawText(String s, int x)
{
  int y = 0;
     for(int i = 0; i < s.length(); i++) {
    led->drawChar(x + i*(fontWidth+space), y, s[i], true, false, 1);
  }
}

Now you can verify an flash the code to the particle photon:


Step 3: Create an SAP HANA Cloud Platform, integration service “iflow”

Sender Adapter:

Content Modifier:

Receiver Adapter:

Now it´s time to deploy the “Integration Flow”, verify the deployment:

Step 4: Post the message to SAP HCP, Integration Service

Ok now just post the message to the SAP HANA Cloud Platform ;o):

And finally lets have a look at the LED matrix:

 

cheers,

Fabian

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.