Difference between revisions of "WaspmoteBLECentral"
From AMTech WikiDocs
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | WaspmoteBLECentral is a thing type that implements a [https://docs.mbed.com/docs/ble-intros/en/latest/Introduction/BLEInDepth/ BLE Central] to communicate with Libelium waspmote model using the BLE protocol. | + | WaspmoteBLECentral is a thing type that implements a [https://docs.mbed.com/docs/ble-intros/en/latest/Introduction/BLEInDepth/ BLE Central] to communicate with Libelium waspmote model using the BLE protocol /amtech/linkeddata/types/composite/entity/waspmoteBLECentral. |
The [https://www.arduino.cc/en/tutorial/sketch Arduino sketch] running on the Libelium waspmote model should construct the BLE advertisement package following the next guideline: | The [https://www.arduino.cc/en/tutorial/sketch Arduino sketch] running on the Libelium waspmote model should construct the BLE advertisement package following the next guideline: | ||
+ | #Write the local attribute containing the device name value "WBLE" BLE.writeLocalAttribute(3, deviceName); | ||
#Build a [https://docs.mbed.com/docs/ble-intros/en/latest/Advanced/CustomGAP/ custom BLE advertisement packet] | #Build a [https://docs.mbed.com/docs/ble-intros/en/latest/Advanced/CustomGAP/ custom BLE advertisement packet] | ||
− | + | ##First byte package size | |
− | + | ##Second byte MANUFACTURER_SPECIFIC_DATA Identifier 0xff | |
− | /* | + | ##Third byte Libelium BLE waspmote identifier LIBELIUM_BLEID |
− | + | ##Fort byte waspmote model identifier example GAS_PRO = 19 (see waspmote model documentation) | |
− | + | ##Fifth byte first 4 bits total number of sensors that will be sent in all advertisement packets last 4 bits the amount of sensors values send in current packet | |
− | + | ##Sixth a message number that should increment with a advertisement packet sent | |
− | + | ##Next bytes must be set with read sensor value a byte with the id of the sensor from Libelium WaspFrame.h and the value(s) read b the sensor | |
− | + | #WaspmoteBLECentral logic uses sensor values type and size from Libelium document data_frame_guide.pdf [http://www.libelium.com/downloads/documentation/data_frame_guide.pdf Sensor ID Table page 13] | |
− | / | + | *The following c function generates a custom BLE advertisement packet for a Gases_PRO waspmote model sending read from 5 sensors SENSOR_ACC, SENSOR_BAT, SENSOR_IN_TEMP, SENSOR_GP_TC and SENSOR_GP_HUM. |
− | + | <syntaxhighlight lang="c"> | |
− | + | #define MSGADDITIONAL_SIZE 29; | |
+ | int buildAdditionalSensors() | ||
+ | { | ||
+ | int ms = 0; ; | ||
+ | memset(advData, 0x00, sizeof(advData)); | ||
+ | advData[ms++]= MSGADDITIONAL_SIZE; | ||
+ | advData[ms++]= AD_TYPE_MANUFACTURER_SPECIFIC_DATA; | ||
+ | advData[ms++] = LIBELIUM_BLEID; | ||
+ | advData[ms++] = Gases_PRO; | ||
+ | advData[ms++] = (uint8_t)(10 | (5 <<4)); | ||
+ | advData[ms++] = msgNumber++; | ||
+ | showValue(msgNumber, "msgNumber", ms); | ||
+ | //1 SENSOR_ACC | ||
+ | advData[ms++] = SENSOR_ACC; | ||
+ | int x = ACC.getX(); | ||
+ | int y = ACC.getY(); | ||
+ | int z = ACC.getZ(); | ||
+ | memcpy( &advData[ms], &x, sizeof(int) ); | ||
+ | ms += sizeof(int); | ||
+ | memcpy( &advData[ms], &y, sizeof(int) ); | ||
+ | ms += sizeof(int); | ||
+ | memcpy( &advData[ms], &z, sizeof(int) ); | ||
+ | ms += sizeof(int); | ||
+ | showACCValues(x,y,z, ms); | ||
+ | //2S ENSOR_BAT | ||
+ | advData[ms++] = SENSOR_BAT; | ||
+ | uint8_t vuint = PWR.getBatteryLevel(); | ||
+ | memcpy( &advData[ms], &vuint, sizeof(uint8_t) ); | ||
+ | ms += sizeof(uint8_t); | ||
+ | showValue(vuint, "SENSOR_BAT", ms); | ||
+ | //3 SENSOR_IN_TEMP | ||
+ | advData[ms++] = SENSOR_IN_TEMP; | ||
+ | float vfloat = RTC.getTemperature(); | ||
+ | memcpy( &advData[ms], &vfloat, sizeof(float) ); | ||
+ | ms += sizeof(float); | ||
+ | showValue(vfloat, "SENSOR_IN_TEMP", ms); | ||
+ | //4 SENSOR_GP_TC | ||
+ | advData[ms++] = SENSOR_GP_TC; | ||
+ | memcpy( &advData[ms], &temperature, sizeof(float) ); | ||
+ | ms += sizeof(float); | ||
+ | showValue(temperature, "SENSOR_GP_TC", ms); | ||
+ | //5 SENSOR_GP_HUM | ||
+ | advData[ms++] = SENSOR_GP_HUM; | ||
+ | memcpy( &advData[ms], &humidity, sizeof(float) ); | ||
+ | ms += sizeof(float); | ||
+ | showValue(humidity, "SENSOR_GP_HUM", ms); | ||
+ | return ms; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | *Smoothing configuration can be set by Waspmote model and sensors id leveraging property readSmoothing | ||
+ | [[File:Waspmote-config.png|950px||thumbnail|left|Waspmote smoothing configuration]] |
Latest revision as of 18:51, 19 July 2017
WaspmoteBLECentral is a thing type that implements a BLE Central to communicate with Libelium waspmote model using the BLE protocol /amtech/linkeddata/types/composite/entity/waspmoteBLECentral. The Arduino sketch running on the Libelium waspmote model should construct the BLE advertisement package following the next guideline:
- Write the local attribute containing the device name value "WBLE" BLE.writeLocalAttribute(3, deviceName);
- Build a custom BLE advertisement packet
- First byte package size
- Second byte MANUFACTURER_SPECIFIC_DATA Identifier 0xff
- Third byte Libelium BLE waspmote identifier LIBELIUM_BLEID
- Fort byte waspmote model identifier example GAS_PRO = 19 (see waspmote model documentation)
- Fifth byte first 4 bits total number of sensors that will be sent in all advertisement packets last 4 bits the amount of sensors values send in current packet
- Sixth a message number that should increment with a advertisement packet sent
- Next bytes must be set with read sensor value a byte with the id of the sensor from Libelium WaspFrame.h and the value(s) read b the sensor
- WaspmoteBLECentral logic uses sensor values type and size from Libelium document data_frame_guide.pdf Sensor ID Table page 13
- The following c function generates a custom BLE advertisement packet for a Gases_PRO waspmote model sending read from 5 sensors SENSOR_ACC, SENSOR_BAT, SENSOR_IN_TEMP, SENSOR_GP_TC and SENSOR_GP_HUM.
#define MSGADDITIONAL_SIZE 29;
int buildAdditionalSensors()
{
int ms = 0; ;
memset(advData, 0x00, sizeof(advData));
advData[ms++]= MSGADDITIONAL_SIZE;
advData[ms++]= AD_TYPE_MANUFACTURER_SPECIFIC_DATA;
advData[ms++] = LIBELIUM_BLEID;
advData[ms++] = Gases_PRO;
advData[ms++] = (uint8_t)(10 | (5 <<4));
advData[ms++] = msgNumber++;
showValue(msgNumber, "msgNumber", ms);
//1 SENSOR_ACC
advData[ms++] = SENSOR_ACC;
int x = ACC.getX();
int y = ACC.getY();
int z = ACC.getZ();
memcpy( &advData[ms], &x, sizeof(int) );
ms += sizeof(int);
memcpy( &advData[ms], &y, sizeof(int) );
ms += sizeof(int);
memcpy( &advData[ms], &z, sizeof(int) );
ms += sizeof(int);
showACCValues(x,y,z, ms);
//2S ENSOR_BAT
advData[ms++] = SENSOR_BAT;
uint8_t vuint = PWR.getBatteryLevel();
memcpy( &advData[ms], &vuint, sizeof(uint8_t) );
ms += sizeof(uint8_t);
showValue(vuint, "SENSOR_BAT", ms);
//3 SENSOR_IN_TEMP
advData[ms++] = SENSOR_IN_TEMP;
float vfloat = RTC.getTemperature();
memcpy( &advData[ms], &vfloat, sizeof(float) );
ms += sizeof(float);
showValue(vfloat, "SENSOR_IN_TEMP", ms);
//4 SENSOR_GP_TC
advData[ms++] = SENSOR_GP_TC;
memcpy( &advData[ms], &temperature, sizeof(float) );
ms += sizeof(float);
showValue(temperature, "SENSOR_GP_TC", ms);
//5 SENSOR_GP_HUM
advData[ms++] = SENSOR_GP_HUM;
memcpy( &advData[ms], &humidity, sizeof(float) );
ms += sizeof(float);
showValue(humidity, "SENSOR_GP_HUM", ms);
return ms;
}
- Smoothing configuration can be set by Waspmote model and sensors id leveraging property readSmoothing