Difference between revisions of "WaspmoteBLECentral"

From AMTech WikiDocs
Jump to: navigation, search
Line 12: Line 12:
 
#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]
 
#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.
 
*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="jsonld">
+
<syntaxhighlight lang="c">
 
#define MSGADDITIONAL_SIZE 29;  
 
#define MSGADDITIONAL_SIZE 29;  
 
int buildAdditionalSensors()
 
int buildAdditionalSensors()

Revision as of 17:29, 19 July 2017

WaspmoteBLECentral is a thing type that implements a BLE Central to communicate with Libelium waspmote model using the BLE protocol. The Arduino sketch running on the Libelium waspmote model should construct the BLE advertisement package following the next guideline:

  1. Write the local attribute containing the device name value "WBLE" BLE.writeLocalAttribute(3, deviceName);
  2. Build a custom BLE advertisement packet
    1. First byte package size
    2. Second byte MANUFACTURER_SPECIFIC_DATA Identifier 0xff
    3. Third byte Libelium BLE waspmote identifier LIBELIUM_BLEID
    4. Fort byte waspmote model identifier example GAS_PRO = 19 (see waspmote model documentation)
    5. 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
    6. Sixth a message number that should increment with a advertisement packet sent
    7. 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
  3. 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;
}