WaspmoteBLECentral

From AMTech WikiDocs
Revision as of 12:55, 19 July 2017 by Carlos (Talk | contribs)

Jump to: navigation, search

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 waspmote model identifier example GAS_PRO = 19 (see waspmote model documentation)
    4. Fort byte first 4 bits a message number from 1-255 last 4 bits the amount of sensors values send in the package
    5. 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
#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;
  //byte result = (byte)(number1 | (number2 << 4));
  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;
}