Skip to content

Instantly share code, notes, and snippets.

@timgrossmann
Created August 1, 2019 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timgrossmann/651ff7f4e7be6b5757b94d55a7200c25 to your computer and use it in GitHub Desktop.
Save timgrossmann/651ff7f4e7be6b5757b94d55a7200c25 to your computer and use it in GitHub Desktop.
package main;
import platforms.xdk110;
setup net : WLAN {
ssid = "TeamVorto";
authentication = Personal(psk = "****");
}
setup backend : MQTT {
transport = net;
url = "mqtts://mqtt.bosch-iot-hub.com";
clientId = "****";
authentication = Login(username = "****", password =
"****");
certificatePath = "C:/Users/****/mqtt_adapter_ssl.pem";
keepAliveInterval = 25;
var telemetry = topic(name = "telemetry", qos = 0);
}
every 5 seconds {
let accelPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/acceleration/properties",
"value" : {
"status": {
"value": {
"x": ${accelerometer.x_axis.read()},
"y": ${accelerometer.y_axis.read()},
"z": ${accelerometer.z_axis.read()}
}
}
}
}`;
let rotationPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/rotation/properties",
"value" : {
"status": {
"value": {
"x": ${gyroscope.x_axis.read()},
"y": ${gyroscope.y_axis.read()},
"z": ${gyroscope.z_axis.read()}
}
}
}
}`;
let magnetPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/magneticStrength/properties",
"value" : {
"status": {
"value": {
"x": : ${magnetometer.x_axis.read()},
"y": ${magnetometer.y_axis.read()},
"z": ${magnetometer.z_axis.read()}
}
}
}
}`;
let acousticsPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/acoustics/properties",
"value" : {
"status": {
"value": {
"currentMeasured" : ${noise_sensor.noise.read()},
"minMeasured" : 0,
"maxMeasured" : 0
}
}
}
}`;
let pressurePayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/pressure/properties",
"value" : {
"status": {
"value": {
"currentMeasured" : ${environment.pressure.read()},
"minMeasured" : 0,
"maxMeasured" : 0
}
}
}
}`;
let temperaturePayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/temperature/properties",
"value" : {
"status": {
"value": {
"currentMeasured" : ${environment.temperature.read()},
"minMeasured" : 0,
"maxMeasured" : 0
}
}
}
}`;
let illumPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/illuminance/properties",
"value" : {
"status": {
"value": {
"currentMeasured" : ${light.intensity.read()},
"minMeasured" : 0,
"maxMeasured" : 0
}
}
}
}`;
let humidityPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/humidity/properties",
"value" : {
"status": {
"value": {
"currentMeasured" : {
"value" : ${environment.humidity.read()}
},
"minMeasured" : {
"value" : 0
},
"maxMeasured" : {
"value" : 0
}
}
}
}
}`;
let batteryPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/humidity/properties",
"value" : {
"status": {
"remainingCapacity" : {
"value" : 67
},
"value" : {
"currentMeasured" : 67,
"minMeasured" : 0,
"maxMeasured" : 0
}
},
"configuration": {
"remainingCapacityAmpHour" : 0
}
}
}
}`;
let connectPayload = `{
"topic": "****/XDK/things/twin/commands/modify",
"headers": { "response-required": "false" },
"path": "/features/connectivity/properties",
"value" : {
"status": {
"rssi": -60,
"snr": 26,
"lastSeen": 0,
"status": "Connected"
}
}
}`;
backend.telemetry.write(accelPayload);
backend.telemetry.write(rotationPayload);
backend.telemetry.write(magnetPayload);
backend.telemetry.write(acousticsPayload);
backend.telemetry.write(pressurePayload);
backend.telemetry.write(temperaturePayload);
backend.telemetry.write(illumPayload);
backend.telemetry.write(humidityPayload);
backend.telemetry.write(batteryPayload);
backend.telemetry.write(connectPayload);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment