Skip to content

Commit

Permalink
mgered changes from freature_orientation to master
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 17, 2019
2 parents dc9f9d4 + e2b7d9f commit 7166515
Show file tree
Hide file tree
Showing 21 changed files with 2,950 additions and 509 deletions.
274 changes: 172 additions & 102 deletions README.md

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions resources/SAMPLE_config.txt

This file was deleted.

2,138 changes: 2,138 additions & 0 deletions resources/XDK.dae

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions resources/XDK_Template_Collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,33 @@
],
"name": "Noise"
},
{
"method": "PUT",
"response": false,
"msgId": "1990",
"api": "INVENTORY",
"byId": false,
"externalIdType": "c8y_Serial",
"mandatoryValues": [],
"customValues": [
{
"path": "c8y_Rotation.pitch.value",
"type": "NUMBER",
"value": null
},
{
"path": "c8y_Rotation.roll.value",
"type": "NUMBER",
"value": null
},
{
"path": "c8y_Rotation.yaw.value",
"type": "NUMBER",
"value": null
}
],
"name": "RotationInventory"
},
{
"method": "PUT",
"response": false,
Expand Down
Binary file added resources/XDK_collada.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/XDK_collada_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 11 additions & 28 deletions resources/config.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
##
# IMPORTANT:
# * values to the right side can't be blank, instead type EMPTY if not used, otherwise bootstrap fails
# * variables not defined explcitly their default-value is used
# * length of file must not excceed 512 bytes
##
WIFISSID=<SSID> | must be defined
WIFIPASSWORD=<PASSWORD OF WIFI> | must be defined
MQTTBROKERNAME=<BROKER NAME>| default-value mqtt.cumulocity.com
MQTTBROKERPORT=<PORT OF MQTT CUMULOCITY BROKER, 8883 FOR TLS, 1883 NO TLS>| default-value 8883
MQTTSECURE=<TRUE FOR TLS, FALSE OTHERWISE> | default-value TRUE
MQTTANONYMOUS=<this property is lony meant to test the agent with other mqtt brokers, cumulocity always requires username password>| default-value FALSE
STREAMRATE=<RATE TO SEND MEASUREMENTS TO C8Y IN MILISECONDS>| default-value 5000
ACCELENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
GYROENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
MAGENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
ENVENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
LIGHTENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
NOISEENABLED=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value false
SNTPNAME=<NAME/IP OF SNTP SERVER>| default-value 0.de.pool.ntp.org
SNTPPORT=<PORT SNTP SEVER>| default-value 123
##
# IMPORTANT:
# * MQTTUSER and MQTTPASSWORD are added as part of the bootstrap mechanism during device registration
# Variables need not be added manually
##
MQTTUSER=<USESNAME IN THE FORM TENANT/USER, RECEIVED IN REGISTRATION>
MQTTPASSWORD=<PASSWORD, RECEIVED IN REGISTRATION>
WIFISSID=<SSID>
WIFIPASSWORD=<PASSWORD OF WIFI>
MQTTBROKERNAME=mqtt.cumulocity.com
MQTTBROKERPORT=8883
STREAMRATE=1000
ACCEL=FALSE
GYRO=FALSE
MAG=FALSE
ENV=TRUE
LIGHT=TRUE
NOISE=TRUE
28 changes: 28 additions & 0 deletions resources/config_DOCUMENTED.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##
# IMPORTANT:
# * values to the right side can't be blank, instead type EMPTY if not used, otherwise bootstrap fails
# * variables not defined explcitly their default-value is used
# * length of file must not excceed 512 bytes
##
WIFISSID=<SSID> | must be defined
WIFIPASSWORD=<PASSWORD OF WIFI> | must be defined
MQTTBROKERNAME=<BROKER NAME>| default-value mqtt.cumulocity.com
MQTTBROKERPORT=<PORT OF MQTT CUMULOCITY BROKER, 8883 FOR TLS, 1883 NO TLS>| default-value 8883
MQTTSECURE=<TRUE FOR TLS, FALSE OTHERWISE> | default-value TRUE
MQTTANONYMOUS=<this property is lony meant to test the agent with other mqtt brokers, cumulocity always requires username password>| default-value FALSE
STREAMRATE=<RATE TO SEND MEASUREMENTS TO C8Y IN MILISECONDS>| default-value 5000
ACCEL=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
GYRO=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
MAG=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
ENV=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
LIGHT=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value true
NOISE=<TRUE TO SEND MEASUREMENTS, FALSE OTHERWISE> | default-value false
SNTPNAME=<NAME/IP OF SNTP SERVER>| default-value 0.de.pool.ntp.org
SNTPPORT=<PORT SNTP SEVER>| default-value 123
##
# IMPORTANT:
# * MQTTUSER and MQTTPASSWORD are added as part of the bootstrap mechanism during device registration
# Variables need not be added manually
##
MQTTUSER=<USESNAME IN THE FORM TENANT/USER, RECEIVED IN REGISTRATION>
MQTTPASSWORD=<PASSWORD, RECEIVED IN REGISTRATION>
2 changes: 1 addition & 1 deletion resources/createShellTemplates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ curl -X POST \
-H 'Accept: application/json' \
--user "$USER" \
-H 'Content-Type: application/json' \
-d '{"type":"c8y_DeviceShellTemplate","c8y_Global":{},"deviceType":"c8y_XDKDevice","name":"enable/disable sensor ... TRUE/FALSE","command":"sensor NOISEENABLED TRUE","category":"sensor"}'
-d '{"type":"c8y_DeviceShellTemplate","c8y_Global":{},"deviceType":"c8y_XDKDevice","name":"enable/disable sensor ... TRUE/FALSE, possible sensors are ACCEL, GYRO, MAG, ENV, LIGHT, NOISE","command":"sensor NOISE TRUE","category":"sensor"}'

curl -X POST \
"$URL" \
Expand Down
11 changes: 11 additions & 0 deletions resources/performanceReportHeap_V01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
everFreeHeap, freeHeap, stackHighWaterMarkMain, stackHighWaterMarkApp, stackSize Main (XDKAppInfo.h), stackSize App (XDKAppInfo.h), configTOTAL_HEAP_SIZE(FreeRTOSconfig.h)
[7200], [9992], [??],[1014], 0900, 1400, 72 * 1024
[6800], [9592], [??],[1014], 1000, 1400, 72 * 1024
[7600],[10392], [??], [804], 1000, 1200, 72 * 1024
[9200],[11992], [??], [614], 0800, 1000, 72 * 1024
[9200],[11992], [??], [614], 0800, 1000, 71 * 1024
[7152], [9944], [??], [614], 0800, 1000, 70 * 1024
[4752], [7544], [??],[1014], 1000, 1400, 70 * 1024
[7152], [9944], [??], [614], 0800, 1200, 70 * 1024
[6352], [9144], [34], [804], 0800, 1000, 70 * 1024
[6752], [9544],[134], [596], 0900, 1000, 70 * 1024
74 changes: 66 additions & 8 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#include "MQTTOperation.h"
#include "MQTTButton.h"

#include "XdkSensorHandle.h"
#include "BCDS_Orientation.h"

/* constant definitions ***************************************************** */

/* local variables ********************************************************** */
Expand Down Expand Up @@ -125,12 +128,11 @@ static void AppController_StartLEDBlinkTimer(int);
static char clientId[] = WIFI_DEFAULT_MAC_CLIENTID;
char deviceId[] = DEVICE_ID;

static xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */


xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */

/* global variables ********************************************************* */
APP_STATUS app_status;
APP_STATUS cmd_status;
/* inline functions ********************************************************* */

/* local functions ********************************************************** */
Expand Down Expand Up @@ -221,6 +223,9 @@ static void AppController_Setup(void * param1, uint32_t param2) {
SensorSetup.Enable.Temp = MQTTCfgParser_IsEnvEnabled();
SensorSetup.Enable.Noise = MQTTCfgParser_IsNoiseEnabled();
retcode = Sensor_Setup(&SensorSetup);
#if ENABLE_SENSOR_TOOLBOX
retcode = Orientation_init(xdkOrientationSensor_Handle);
#endif
}
//delay start
vTaskDelay(pdMS_TO_TICKS(4000));
Expand Down Expand Up @@ -320,7 +325,6 @@ static void AppController_Fire(void* pvParameters)
MqttCredentials.Password = MQTTCfgParser_GetMqttPassword();
MqttCredentials.Anonymous = MQTTCfgParser_IsMqttAnonymous();
MQTTOperation_Init(MqttSetupInfo, MqttConnectInfo, MqttCredentials, SensorSetup);

} else {
MQTTRegistration_Init(MqttSetupInfo, MqttConnectInfo);
}
Expand All @@ -336,12 +340,12 @@ static void AppController_SetClientId(void) {

memset(clientId, NUMBER_UINT8_ZERO, strlen(clientId));
//changed
sprintf(clientId, "d:XDK_%02X_%02X_%02X_%02X_%02X_%02X", _macVal[0],
sprintf(clientId, "d:%02X%02X%02X%02X%02X%02X", _macVal[0],
_macVal[1], _macVal[2], _macVal[3], _macVal[4], _macVal[5]);

memset(deviceId, NUMBER_UINT8_ZERO, strlen(deviceId));
//changed
sprintf(deviceId, "XDK_%02X_%02X_%02X_%02X_%02X_%02X", _macVal[0],
sprintf(deviceId, "%02X%02X%02X%02X%02X%02X", _macVal[0],
_macVal[1], _macVal[2], _macVal[3], _macVal[4], _macVal[5]);

MqttConnectInfo.ClientId = clientId;
Expand Down Expand Up @@ -390,7 +394,22 @@ static void AppController_ToogleLEDCallback(xTimerHandle xTimer) {
default:
LOG_AT_WARNING(("AppController: Unknown status\n"));
break;

}
switch(cmd_status) {
case APP_STATUS_COMMAND_RECEIVED:
BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_TOGGLE);
cmd_status = APP_STATUS_COMMAND_CONFIRMED;
break;
case APP_STATUS_COMMAND_CONFIRMED:
BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_TOGGLE);
cmd_status = APP_STATUS_STARTED;
break;
case APP_STATUS_STARTED:
// do nothing
break;
default:
LOG_AT_WARNING(("AppController: Unknown status\n"));
break;
}
}

Expand All @@ -404,7 +423,38 @@ static void AppController_StartLEDBlinkTimer(int period) {
xTimerStart(timerHandle, UINT32_C(0xffff));
}


Retcode_T AppController_SyncTime() {
uint64_t sntpTimeStampFromServer = 0UL;
uint16_t sntpAttemps = 0UL;
Retcode_T retcode = RETCODE_OK;
/* We Synchronize the node with the SNTP server for time-stamp.
* Since there is no point in doing a HTTPS communication without a valid time */
do {
retcode = SNTP_GetTimeFromServer(&sntpTimeStampFromServer,
APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT);
if ((RETCODE_OK != retcode) || (0UL == sntpTimeStampFromServer)) {
LOG_AT_WARNING(
("MQTTOperation: SNTP server time was not synchronized. Retrying...\r\n"));
}
sntpAttemps++;
vTaskDelay(pdMS_TO_TICKS(2000));
} while (0UL == sntpTimeStampFromServer && sntpAttemps < 3); // only try to sync time 5 times
if (0UL == sntpTimeStampFromServer) {
sntpTimeStampFromServer = 1572566400UL; // use default time 1. Nov 2019 00:00:00 UTC
SNTP_SetTime(sntpTimeStampFromServer);
LOG_AT_WARNING(
("MQTTOperation: Using fixed timestamp 1. Nov 2019 00:00:00 UTC, SNTP sync not possible\r\n"));
retcode = RETCODE_OK; // clear return code
}
//uint8_t * timeBuffer = (uint8_t *) &sntpTimeStampFromServer;
//LOG_AT_TRACE(("MQTTOperation: SNTP time: %d,%d,%d,%d,%d,%d,%d,%d\r\n", timeBuffer[0], timeBuffer[1], timeBuffer[2], timeBuffer[3],timeBuffer[4],timeBuffer[5],timeBuffer[6],timeBuffer[7]));
struct tm time;
char timezoneISO8601format[40];
TimeStamp_SecsToTm(sntpTimeStampFromServer, &time);
TimeStamp_TmToIso8601(&time, timezoneISO8601format, 40);
BCDS_UNUSED(sntpTimeStampFromServer); /* Copy of sntpTimeStampFromServer will be used be HTTPS for TLS handshake */
return retcode;
}

/* global functions ********************************************************* */

Expand All @@ -418,6 +468,7 @@ void AppController_Init(void * cmdProcessorHandle, uint32_t param2) {

// start status LED indicator
AppController_SetStatus(APP_STATUS_STARTED);
AppController_SetCmdStatus(APP_STATUS_STARTED);
AppController_StartLEDBlinkTimer (500);

// init battery monitor
Expand Down Expand Up @@ -447,5 +498,12 @@ uint8_t AppController_GetStatus(void) {
return app_status;
}

void AppController_SetCmdStatus( uint8_t status) {
cmd_status = status;
}

uint8_t AppController_GetCmdStatus(void) {
return cmd_status;
}


Loading

0 comments on commit 7166515

Please sign in to comment.