#include "CumulocityPlatform.h"
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <I2C.h>
/*
*
* !!! Device control feature is not working with avr-gcc 4.3.2
* !!! Confirmed to be working with avr-gcc 4.7.2
*
*/
CumulocityPlatform cPlatform("developer.cumulocity.com", "tenant", "user", "password", "application key");
GSMModule* mod;
char operation[50];
char operationName[15];
int result;
byte x;
void setup() {
Serial.begin(19200);
I2c.begin();
Serial.println(F("Start"));
pinMode(A3, INPUT); // Sensor plugged to A3 header
mod = new GSMModule();
Serial.println(F("Attaching GPRS..."));
if(mod->attachGPRS("m2m.business", "", "")) {
Serial.println(F("GPRS attached."));
cPlatform.setGSM(mod);
char id[8];
Serial.println(F("Registering a device..."));
int result = cPlatform.registerDevice("LEDMatrix", id, 8);
if(result<0) {
Serial.println(F("Registration error."));
while(true);
} else {
Serial.print(F("Arduino registered with id: "));
Serial.println(id);
}
//char id[8]="136500";
} else {
Serial.println(F("Could not attach GPRS."));
while(true);
}
}
void loop() {
Serial.println(F("\nRetrieving operation from server..."));
if((result = cPlatform.getPendingOperationFromServer(operationName, 15, operation, 50)) > 0) {
executeOperation();
if((result = cPlatform.markOperationCompleted()) > 0) {
Serial.println(F("Operation marked as completed"));
} else {
Serial.println(F("Operation update failed."));
}
} else if(result < 0) {
Serial.println(F("Operation retrieval failed."));
} else {
Serial.println(F("No operation awaiting."));
}
delay(30000);
}
void executeOperation() {
Serial.println(F("Executing operation:"));
//Code for Wire libraray and one LED matrix
// Serial.println(operationName);
// Serial.println(operation);
// Wire.beginTransmission(9); // transmit to device #9
//for(int i=0;i<strlen(operation); i++){
//x=byte(operation[i]);
//Wire.write(x); // sends x
//delay(100);
//Wire.write(x); // sends x
//}
//Wire.endTransmission(); // stop transmitting
//Code for I2C library
for(int j=13;j>8; j--){
I2c.write(j,operation);
delay(450);
}
}