Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 69:237c01eb36c2, committed 2014-12-13
- Comitter:
- vwochnik
- Date:
- Sat Dec 13 16:07:07 2014 +0000
- Parent:
- 68:0dc778a16d0d
- Child:
- 70:f489ca11f254
- Commit message:
- delFile bug fixed
Changed in this revision
--- a/DeviceIntegration.cpp Sat Dec 06 19:47:23 2014 +0000 +++ b/DeviceIntegration.cpp Sat Dec 13 16:07:07 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_SupportedOperations\"\":[\"\"c8y_Relay\"\",\"\"c8y_Configuration\"\",\"\"c8y_Message\"\"],\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":15},\"\"c8y_IsDevice\"\":{},\"\"com_cumulocity_model_Agent\"\":{}}\"\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_SupportedOperations\"\":[\"\"c8y_Relay\"\",\"\"c8y_Configuration\"\",\"\"c8y_Message\"\"],\"\"c8y_IsDevice\"\":{},\"\"com_cumulocity_model_Agent\"\":{}}\"\r\n")) return false; // Get device id
--- a/MbedAgent.h Sat Dec 06 19:47:23 2014 +0000 +++ b/MbedAgent.h Sat Dec 13 16:07:07 2014 +0000 @@ -22,7 +22,7 @@ #define MBED_AGENT_HOST "developer.cumulocity.com" #define MBED_AGENT_PORT 80 -#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.5.0" +#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.5.1" class MbedAgent {
--- a/config/ConfigurationProperties.cpp Sat Dec 06 19:47:23 2014 +0000 +++ b/config/ConfigurationProperties.cpp Sat Dec 13 16:07:07 2014 +0000 @@ -10,7 +10,12 @@ bool ConfigurationProperties::resetConfiguration() { - return _deviceConfiguration.set("interval", CONFIGURATION_PROPERTY_INTERVAL); + return (_deviceConfiguration.clear(), _deviceConfiguration.set("interval", CONFIGURATION_PROPERTY_INTERVAL)); +} + +bool ConfigurationProperties::validateProperties() +{ + return (readInterval() > 0); } int ConfigurationProperties::readInterval()
--- a/config/ConfigurationProperties.h Sat Dec 06 19:47:23 2014 +0000 +++ b/config/ConfigurationProperties.h Sat Dec 13 16:07:07 2014 +0000 @@ -12,6 +12,7 @@ ConfigurationProperties(DeviceConfiguration&); bool resetConfiguration(); + bool validateProperties(); int readInterval();
--- a/config/ConfigurationSynchronization.cpp Sat Dec 06 19:47:23 2014 +0000 +++ b/config/ConfigurationSynchronization.cpp Sat Dec 13 16:07:07 2014 +0000 @@ -22,8 +22,8 @@ return false; // Update Configuration - // Usage: 130,<DEVICE/ID>,<CONFIG/STRING> - if (!_tpl.add("10,130,PUT,/inventory/managedObjects/%%,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,UNSIGNED STRING,\"{\"\"c8y_Configuration\"\":{\"\"config\"\":\"\"%%\"\"}}\"\r\n")) + // Usage: 130,<DEVICE/ID>,<CONFIG/STRING>,<RESPONSIBILITY> + if (!_tpl.add("10,130,PUT,/inventory/managedObjects/%%,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,UNSIGNED STRING NUMBER,\"{\"\"c8y_Configuration\"\":{\"\"config\"\":\"\"%%\"\"},\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":%%}}\"\r\n")) return false; _init = true; @@ -32,7 +32,7 @@ bool ConfigurationSynchronization::integrate() { - if (!loadConfiguration()) { + if ((!loadConfiguration()) || (!_configurationProperties.validateProperties())) { if ((!_configurationProperties.resetConfiguration()) || (!updateDeviceObject()) || (!saveConfiguration())) return false; } else { @@ -60,6 +60,11 @@ if (!_deviceConfiguration.read(cfg)) return false; + if (!_configurationProperties.validateProperties()) { + loadConfiguration(); + return false; + } + _changed = true; return true; } @@ -77,7 +82,8 @@ IntegerValue msgId(130); IntegerValue deviceId(_deviceId); CharValue config(buf); - if ((!record.add(msgId)) || (!record.add(deviceId)) || (!record.add(config))) + IntegerValue responsibility(_configurationProperties.readInterval()); + if ((!record.add(msgId)) || (!record.add(deviceId)) || (!record.add(config)) || (!record.add(responsibility))) return false; if (_client.send(record) != SMARTREST_SUCCESS) {
--- a/io/DeviceMemory.cpp Sat Dec 06 19:47:23 2014 +0000 +++ b/io/DeviceMemory.cpp Sat Dec 13 16:07:07 2014 +0000 @@ -17,7 +17,7 @@ if ((res = _mdm.readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer))) < 0) return false; - + buffer[(size_t)res] = '\0'; sscanf(buffer, "%s\n%s\n%n", username, password, &len2); return res == len2; @@ -31,7 +31,8 @@ if ((res < 0) || (res >= sizeof(buffer))) return false; - return ((_mdm.delFile(PLATFORM_CREDENTIALS_FILE)) && (res == _mdm.writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res))); + resetPlatformCredentials(); + return (res == _mdm.writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res)); } bool DeviceMemory::resetPlatformCredentials() @@ -56,7 +57,9 @@ size_t len; len = strlen(cfg); - return ((_mdm.delFile(CONFIGURATION_FILE)) && (_mdm.writeFile(CONFIGURATION_FILE, cfg, len) == len)); + + resetConfiguration(); + return (_mdm.writeFile(CONFIGURATION_FILE, cfg, len) == len); } bool DeviceMemory::resetConfiguration()