BigW Consortium Gitlab

Commit ab70d909 by David Frey

YellowSensorToCloud: fix minor formatting issues

parent 448e6cc5
......@@ -8,7 +8,7 @@ requires:
{
api:
{
io = io.api
io = io.api
mangOH_bme680.api
}
......
......@@ -5,18 +5,23 @@
/// Input resource path
#define RES_PATH_VALUE "bme/value"
#define RES_PATH_CONFIG "bme/config"
#define JSON_EXAMPLE "{\"timestamp\":1,\"iaqValue\":1,\"iaqAccuracy\":1,\"co2EquivalentValue\":1,"\
#define VALUE_EXAMPLE "{\"timestamp\":1,\"iaqValue\":1,\"iaqAccuracy\":1,\"co2EquivalentValue\":1,"\
"\"co2EquivalentAccuracy\":1,\"breathVocValue\":1,\"breathVocAccuracy\":1,"\
"\"pressure\":1,\"temperature\":1,\"humidity\":1 }"
static void BmeConfigPushHandler(double timestamp, const char *jsonStr, void *context)
{
/*
/*
* Expect jsonStr in the form:
* {"enableIaq": True, "enableCo2Equivalent" : true, "enableBreathVoc" : false,
* "enablePressure" : false, "enableTemperature": true, "enableHumidity" :false,
* " MANGOH_BME680_SAMPLING_RATE_LP": 3}
*
* {
* "samplingRate": "SAMPLING_RATE_LP",
* "enableIaq": true,
* "enableCo2Equivalent": true,
* "enableBreathVoc": true,
* "enablePressure": true,
* "enableTemperature": true,
* "enableHumidity": true
* }
*/
json_error_t loadError;
......@@ -29,19 +34,19 @@ static void BmeConfigPushHandler(double timestamp, const char *jsonStr, void *co
}
const char *samplingRate;
int enableIaq;
int enableCo2Equivalent;
int enableBreathVoc;
int enablePressure ;
int enableTemperature;
int enableHumidity;
int samplingRateEnum;
int enableIaq;
int enableCo2Equivalent;
int enableBreathVoc;
int enablePressure ;
int enableTemperature;
int enableHumidity;
int samplingRateEnum;
const int unpackRes = json_unpack(
json, "{s:s, s:b, s:b, s:b, s:b, s:b, s:b}",
"samplingRate", &samplingRate, "enableIaq", &enableIaq,"enableCo2Equivalent", &enableCo2Equivalent,
"enableBreathVoc", &enableBreathVoc,"enablePressure", &enablePressure,"enableTemperature", &enableTemperature,
"enableHumidity", &enableHumidity);
json, "{s:s, s:b, s:b, s:b, s:b, s:b, s:b}", "samplingRate", &samplingRate, "enableIaq",
&enableIaq, "enableCo2Equivalent", &enableCo2Equivalent, "enableBreathVoc",
&enableBreathVoc, "enablePressure", &enablePressure, "enableTemperature",
&enableTemperature, "enableHumidity", &enableHumidity);
if (unpackRes)
{
......@@ -66,7 +71,7 @@ static void BmeConfigPushHandler(double timestamp, const char *jsonStr, void *co
LE_ERROR("Bad sampling rate \"%s\"", samplingRate);
goto cleanup;
}
LE_ASSERT_OK(mangOH_bme680_Configure(
samplingRateEnum,
enableIaq,
......@@ -81,79 +86,67 @@ static void BmeConfigPushHandler(double timestamp, const char *jsonStr, void *co
}
static void SensorReadingHandler(
static void SensorReadingHandler
(
const mangOH_bme680_Reading_t *reading,
void* context
)
{
LE_INFO("test1");
json_t *jsonBme = json_object();
json_object_set_new(jsonBme, "timestamp", json_real(reading->timestamp));
LE_INFO("test2");
json_object_set_new(jsonBme, "timestamp", json_real(reading->timestamp));
if( reading->iaq.valid)
if (reading->iaq.valid)
{
json_object_set_new(jsonBme, "iaqValue", json_real(reading->iaq.value));
json_object_set_new(jsonBme, "iaqAccuracy", json_integer(reading->iaq.accuracy));
}
if(reading->co2Equivalent.valid)
if (reading->co2Equivalent.valid)
{
json_object_set_new(jsonBme, "co2EquivalentValue", json_real(reading->co2Equivalent.value));
json_object_set_new(jsonBme, "co2EquivalentAccuracy", json_integer(reading->co2Equivalent.accuracy));
json_object_set_new(jsonBme, "co2EquivalentAccuracy",
json_integer(reading->co2Equivalent.accuracy));
}
if(reading->breathVoc.valid)
if (reading->breathVoc.valid)
{
json_object_set_new(jsonBme, "breathVocValue", json_real(reading->breathVoc.value));
json_object_set_new(jsonBme, "breathVocAccuracy", json_integer(reading->breathVoc.accuracy));
}
if(reading->pressure.valid)
if (reading->pressure.valid)
{
json_object_set_new(jsonBme, "pressure", json_real(reading->pressure.value));
}
if(reading->temperature.valid)
if (reading->temperature.valid)
{
json_object_set_new(jsonBme, "temperature", json_real( reading->temperature.value));
}
if(reading->humidity.valid)
if (reading->humidity.valid)
{
json_object_set_new(jsonBme, "humidity", json_real(reading->humidity.value));
}
char* value = json_dumps(jsonBme, JSON_COMPACT);
char *value = json_dumps(jsonBme, JSON_COMPACT);
LE_ASSERT(value != NULL);
json_decref(jsonBme);
io_PushJson(RES_PATH_VALUE, IO_NOW, value);
free(value);
json_decref(jsonBme);
}
COMPONENT_INIT
{
le_result_t res = io_CreateOutput(RES_PATH_CONFIG, IO_DATA_TYPE_JSON,"");
le_result_t res = io_CreateOutput(RES_PATH_CONFIG, IO_DATA_TYPE_JSON, "");
LE_FATAL_IF(res != LE_OK, "Couldn't create config data hub output - %s", LE_RESULT_TXT(res));
// io_MarkOptional(RES_PATH_CONFIG);
// io_MarkOptional(RES_PATH_CONFIG);
io_AddJsonPushHandler(RES_PATH_CONFIG, BmeConfigPushHandler, NULL);
LE_ASSERT_OK(io_CreateInput(RES_PATH_VALUE, IO_DATA_TYPE_JSON, ""));
io_SetJsonExample(RES_PATH_VALUE, JSON_EXAMPLE);
mangOH_bme680_AddSensorReadingHandler(SensorReadingHandler, NULL);
io_SetJsonExample(RES_PATH_VALUE, VALUE_EXAMPLE);
mangOH_bme680_AddSensorReadingHandler(SensorReadingHandler, NULL);
}
sandboxed: true
start: auto
start: auto
version: 0.0
extern:
{
imu = yellowSensor.imu.imu
imuTemp = yellowSensor.imu.temperature
light = yellowSensor.light.light
magn = yellowSensor.magnetometer.magn
imu = yellowSensor.imu.imu
imuTemp = yellowSensor.imu.temperature
light = yellowSensor.light.light
magn = yellowSensor.magnetometer.magn
}
executables:
{
yellowSensor = (
components/sensors/imu
components/sensors/magnetometer
components/sensors/light
components/sensors/bsec
)
yellowSensor = (
components/sensors/imu
components/sensors/magnetometer
components/sensors/light
components/sensors/bsec
)
}
processes:
......@@ -30,13 +30,12 @@ processes:
envVars:
{
LE_LOG_LEVEL = DEBUG
LD_LIBRARY_PATH = /legato/systems/current/apps/yellowSensor/read-only/usr/lib
LD_LIBRARY_PATH = /legato/systems/current/apps/yellowSensor/read-only/usr/lib
}
}
bindings:
{
yellowSensor.periodicSensor.dhubIO -> dataHub.io
yellowSensor.imu.dhubIO -> dataHub.io
yellowSensor.light.dhubIO -> dataHub.io
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment