Invoking ICApps
2 min read
Using the SDK
final Client rapidomize = new Client(appId, token, Transport.MQTT);
// Update device configuration properties using HTTP requests
String device = "{\"att\": [{\"n\":\"serial\", \"v\":\"1-000-xyz123\"}, {\"n\":\"type\", \"v\":1}, " +
" {\"n\":\"model\", \"v\":\"m-102\"}]," +
" \"prop\":[{\"n\":\"temperature\", \"dt\":\"double\", \"rwx\":1}," +
" {\"n\":\"valve\", \"dt\":\"string\", \"rwx\":3}]}";
rapidomize.register(Json.fromJson(device), cbReq);
// Read device configuration properties
rapidomize.read(new Json("n", "color"), new AckHandler() {
boolean shutdown=false;
@Override
public void ack(Json res){
System.out.println("response: "+res);
}
@Override
public boolean shutdown() {
return shutdown;
}
});
// Trigger ICApp by Geofence
Json location = new Json("lat", 8.1, "lng", 70.3);
Json event = new Json("n", "loc","loc", location);
rapidomize.trigger(icappId, event);
// Trigger a ICApp without responses (fire and forget)
rapidomize.trigger(icappId, "{\"a\":\"b\"}");
// Trigger a ICApp having a response.
rapidomize.trigger(icappId, new Json("id", "2", "n", "asdsd", "val", 10), new AckHandler() {
boolean shutdown=false;
@Override
public void ack(Json res){
System.out.println("response: "+res);
}
@Override
public boolean shutdown() {
return shutdown;
}
});
// Trigger api endpoint using events. events validated by api gateway
Json ev = new Json(true);
ev.add(new Json("loc", new Json("lat", 6.84699914466525, "lng", 80.00123977661133)));
ev.add(new Json("n","appEv","temperature", Math.random() * 100));
ev.add(new Json("color","red"));
ev.add(new Json("new-sensor",65));
rapidomize.event(ev);
// Handle server requests.
rapidomize.connect(new DeviceActionHandler(rapidomize));
String a = "";
const rapidomize = require('../../dist/rapidomize');
/* initialize the library with appId and token */
rapidomize.init(APP_ID, TOKEN);
/* track an event */
rapidomize.event('register', {
'type': 'click',
'wait': '160s'
}, ICAPP_ID);
/* Trigger an ICApp */
rapidomize.trigger(ICAPP_ID, {
to: 'sample@abc.com',
from: 'noreply@my-site.com',
subject: 'Test Subject',
body: 'Test body'
},
//call back
{
ack: (res) => {
console.log('res', res)
},
err: (err) => {
console.log('err', err.err)
}
}
);
String a = "";
String a = "";