Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 57:4af5f1bec3a6, committed 2014-10-23
- Comitter:
- vwochnik
- Date:
- Thu Oct 23 14:21:26 2014 +0000
- Parent:
- 56:4d6e34f1589d
- Child:
- 58:4cc0ae5a7058
- Commit message:
- Operation support skeleton
Changed in this revision
--- a/DeviceIntegration.cpp Thu Oct 23 12:59:37 2014 +0000
+++ b/DeviceIntegration.cpp Thu Oct 23 14:21:26 2014 +0000
@@ -30,7 +30,7 @@
// Create device
// Usage: 101,<SERIAL/NR>
- if (!_tpl.add("10,101,POST,/inventory/managedObjects,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,STRING,\"{\"\"name\"\":\"\"Mbed Test Device\"\",\"\"type\"\":\"\"com_ublox_C027_REV-A\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Ublox C027\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\",\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_AnalogMeasurement\"\",\"\"c8y_MotionMeasurement\"\",\"\"c8y_AnalogMeasurement\"\"],\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":15},\"\"c8y_IsDevice\"\":{}}\"\r\n"))
+ if (!_tpl.add("10,101,POST,/inventory/managedObjects,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,STRING,\"{\"\"name\"\":\"\"Mbed Test Device\"\",\"\"type\"\":\"\"com_ublox_C027_REV-A\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Ublox C027\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\",\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_AnalogMeasurement\"\",\"\"c8y_MotionMeasurement\"\",\"\"c8y_AnalogMeasurement\"\"],\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":15},\"\"c8y_IsDevice\"\":{},\"\"com_cumulocity_model_Agent\"\":{}}\"\r\n"))
return false;
// Get device id
--- a/MbedAgent.cpp Thu Oct 23 12:59:37 2014 +0000
+++ b/MbedAgent.cpp Thu Oct 23 14:21:26 2014 +0000
@@ -13,6 +13,7 @@
_accelerationMeasurement(_client, _tpl, _deviceId, _io.accelerometer()),
_analogMeasurement(_client, _tpl, _deviceId, _io.analog1(), _io.analog2()),
_locationUpdate(_client, _tpl, _deviceId, _io.gpsTracker()),
+ _operationSupport(_client, _tpl, _deviceId),
_deviceId(0)
{
}
@@ -24,7 +25,8 @@
(!_temperatureMeasurement.init()) ||
(!_accelerationMeasurement.init()) ||
(!_analogMeasurement.init()) ||
- (!_locationUpdate.init())) {
+ (!_locationUpdate.init()) ||
+ (!_operationSupport.init())) {
puts("Initialization failed.");
return false;
}
@@ -65,6 +67,7 @@
_accelerationMeasurement.run();
_analogMeasurement.run();
_locationUpdate.run();
+ _operationSupport.run();
while (timer.read() < MBED_AGENT_INTERVAL) {
Thread::yield();
--- a/MbedAgent.h Thu Oct 23 12:59:37 2014 +0000
+++ b/MbedAgent.h Thu Oct 23 14:21:26 2014 +0000
@@ -14,10 +14,11 @@
#include "AccelerationMeasurement.h"
#include "AnalogMeasurement.h"
#include "LocationUpdate.h"
+#include "OperationSupport.h"
#define MBED_AGENT_HOST "developer.cumulocity.com"
#define MBED_AGENT_PORT 80
-#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.0.5"
+#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.1.0"
#define MBED_AGENT_INTERVAL 60.0
class MbedAgent
@@ -44,6 +45,7 @@
AccelerationMeasurement _accelerationMeasurement;
AnalogMeasurement _analogMeasurement;
LocationUpdate _locationUpdate;
+ OperationSupport _operationSupport;
long _deviceId;
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/operation/OperationSupport.cpp Thu Oct 23 14:21:26 2014 +0000
@@ -0,0 +1,45 @@
+#include "OperationSupport.h"
+#include "ComposedRecord.h"
+#include "CharValue.h"
+#include "IntegerValue.h"
+
+OperationSupport::OperationSupport(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId) :
+ _client(client),
+ _tpl(tpl),
+ _deviceId(deviceId)
+{
+ _init = false;
+}
+
+bool OperationSupport::init()
+{
+ if (_init)
+ return false;
+
+ // Get pending operations
+ // USAGE: 110,<DEVICE/ID>
+ if (!_tpl.add("10,110,GET,/devicecontrol/operations?status=PENDING&deviceId=%%&pageSize=100,,application/vnd.com.nsn.cumulocity.operationCollection+json,%%,UNSIGNED,\r\n"))
+ return false;
+
+ // Set operation state
+ // USAGE: 110,<OPERATION/ID>,<STATE>
+ if (!_tpl.add("10,110,PUT,/devicecontrol/operations/%%,application/vnd.com.nsn.cumulocity.operation+json,application/vnd.com.nsn.cumulocity.operation+json,%%,UNSIGNED STRING,\"{\"\"status\"\":\"\"%%\"\"}\"\r\n"))
+ return false;
+
+ // Get operations
+ // Response: 210,<OPERATION/ID>,<STATUS>
+ if (!_tpl.add("11,210,\"$.operations\",,\"$.id\",\"$.status\"\r\n"))
+ return false;
+
+ // Get operation
+ // Response: 211,<OPERATION/ID>,<STATUS>
+ if (!_tpl.add("11,211,,\"$.deviceId\",\"$.id\",\"$.status\"\r\n"))
+ return false;
+
+ _init = true;
+ return true;
+}
+
+bool OperationSupport::run()
+{
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/operation/OperationSupport.h Thu Oct 23 14:21:26 2014 +0000
@@ -0,0 +1,22 @@
+#ifndef OPERATIONSUPPORT_H
+#define OPERATIONSUPPORT_H
+
+#include "AbstractSmartRest.h"
+#include "SmartRestTemplate.h"
+
+class OperationSupport
+{
+public:
+ OperationSupport(AbstractSmartRest&, SmartRestTemplate&, long&);
+
+ bool init();
+ bool run();
+
+private:
+ bool _init;
+ long& _deviceId;
+ SmartRestTemplate& _tpl;
+ AbstractSmartRest& _client;
+};
+
+#endif
\ No newline at end of file
