![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: main.cpp
- Revision:
- 53:c6942af186d7
- Parent:
- 52:bd7678eade77
- Child:
- 54:2840f2d50734
diff -r bd7678eade77 -r c6942af186d7 main.cpp --- a/main.cpp Wed May 29 22:59:12 2019 +0000 +++ b/main.cpp Wed May 29 23:59:56 2019 +0000 @@ -84,6 +84,7 @@ time_t RET_debug_offat = 0; float RET_voltage = 0.0; float RET_temperature = 0.0; +float RET_humidity = 0.0; float RET_temperature_max = -999.0; //Within broadcast frame. Set inital value to low float RET_temperature_min = 999.0; //Within broadcase frame. Set inital value to high uint32_t RET_modemBrownOutCountInSession = 0; @@ -116,6 +117,7 @@ uint8_t RET_bleAdv_flags = 0; char RET_closestLocationTag_id[17]; int RET_closestLocationTag_rssi = 999; + int RET_closestBT04Tag_rssi = 999; bool RET_locationTag_present = false; bool RET_detector_present = false; const uint8_t bleAdv_motionTriggeredinFrame_flag = 0b01000000; @@ -387,6 +389,7 @@ GLOBAL_accel_healthy = false; RET_motionTriggeredinFrame = false; RET_modemBrownOutCountInSession = 0; + RET_humidity = 99.0f; memset(GLOBAL_exceptionString,0x00,sizeof(GLOBAL_exceptionString)); } void healthCheck() { @@ -590,14 +593,47 @@ RET_closestLocationTag_rssi = tag_rssi; memcpy(RET_closestLocationTag_id, beacon_identifier, sizeof(RET_closestLocationTag_id)); RET_locationTag_present = true; - //if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Location Tag Present: %s, rssi: %d",closestLocationTag_id, closestLocationTag_rssi);debug_exe();} + if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Location Tag Present: %s, rssi: %d",RET_closestLocationTag_id, RET_closestLocationTag_rssi);debug_exe();} } } break; } case BLE_SERVICEID_BT04 : { - //nothing yet + //get serial + //char serial[9]; + //snprintf(serial, sizeof(serial), "%02x%02x%02x%02x", params->advertisingData[11], params->advertisingData[12], params->advertisingData[13], params->advertisingData[14]); + //if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"Serial: %s", serial);debug_exe();} + + //get battery + //int battery = params->advertisingData[15]; + //if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"Battery: %i", battery);debug_exe();} + + //get temperature positive + /* + bool temppositive = !(params->advertisingData[17] & 0b01000000); + float temperature = + ( + ((params->advertisingData[17] & 0b00111111) << 8) | + ((params->advertisingData[18] & 0b11111111)) + ) / 100.0; + if (!temppositive) temperature = -temperature; + //if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"Temp: %f", temperature);debug_exe();} + */ + + //get humidity + int tag_rssi = params->rssi * -1; //to convert to positive number + if (tag_rssi < RET_closestBT04Tag_rssi) { + RET_humidity = + ( + ((params->advertisingData[19] & 0b01111111) << 8) | + ((params->advertisingData[20] & 0b11111111)) + ) / 100.0; + if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Humidity Tag Present: %f",RET_humidity);debug_exe();} + } + //rssi + //if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"Rssi: %i", params->rssi);debug_exe();} + break; } case BLE_SERVICEID_PFDETECTOR1 : @@ -626,7 +662,7 @@ params->advertisingData[19], params->advertisingData[20]); //if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), " Mac: [%02x%02x%02x%02x%02x%02x], rssi: %d, AType: %u, Id: %s",params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],params->rssi, pAdvData->dataType, ble_advdata);debug_exe();} - //if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Detector @rssi: %d",params->rssi);debug_exe();} + if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Detector @rssi: %d",params->rssi);debug_exe();} if (params->rssi >= -75) { RET_detector_present = true; } @@ -638,8 +674,8 @@ void bleConfigureScan(void) { //configure scan - //myble.gap().setScanParams(60,30); //scan interval //scan window - myble.gap().setScanParams(100,100); //scan interval //scan window + myble.gap().setScanParams(60,30); //scan interval //scan window + //myble.gap().setScanParams(100,100); //scan interval //scan window myble.gap().startScan(bleAdvertisementCallback); } void bleStopScan(void) @@ -1030,11 +1066,11 @@ char bytesToSend[160]; //Check for Nearby Location Beacons + memset(RET_closestLocationTag_id, 0x00, sizeof(RET_closestLocationTag_id)); + RET_closestLocationTag_rssi = 999; + RET_locationTag_present = false; + RET_detector_present = false; #if BLE_ENABLED - memset(RET_closestLocationTag_id, 0x00, sizeof(RET_closestLocationTag_id)); - RET_closestLocationTag_rssi = 999; - RET_locationTag_present = false; - RET_detector_present = false; if (RET_setting_beacon_scan == 1 && RET_setting_location_mode != LOCATION_MODE_REALTIME) { LowPowerTimer bleScan_t; bleScan_t.start(); @@ -1053,7 +1089,7 @@ bleScan_runtime = (bleScan_t.read_ms() - bleScan_startmillis); myble.waitForEvent(); // low power wait for event } - //if (LocationTag_preset) if(RET_debug){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "LocationTag: %s, rssi: %d",closestLocationTag_id, closestLocationTag_rssi);debug_exe();} + if (RET_locationTag_present && RET_debug) {debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "LocationTag: %s, rssi: %d",RET_closestLocationTag_id, RET_closestLocationTag_rssi);debug_exe();} } bleScan_t.stop(); myble.gap().stopScan(); @@ -1076,12 +1112,17 @@ char locString[70]; int gpsStartTime = RET_RTCunixtime; - //check if we have moved since last post, if not use same valid gps fix if exists - if (RET_motionStateOnInLocTXInterval == false && GLOBAL_have_GPSlocString_prev == true) { - memcpy(locString, GLOBAL_GPSlocString_prev, sizeof(locString)); - addToExceptionString("P"); + if (RET_locationTag_present) { + snprintf(locString, sizeof(locString), ",l:%s.%d\0",RET_closestLocationTag_id,RET_closestLocationTag_rssi); + addToExceptionString("BL"); } else { - memcpy(locString, modem.getLocation(RET_setting_location_accuracy, RET_setting_location_timeout, RET_GPSFailCount, RET_NetworkFailCount), sizeof(locString)); + //check if we have moved since last post, if not use same valid gps fix if exists + if (RET_motionStateOnInLocTXInterval == false && GLOBAL_have_GPSlocString_prev == true) { + memcpy(locString, GLOBAL_GPSlocString_prev, sizeof(locString)); + addToExceptionString("P"); + } else { + memcpy(locString, modem.getLocation(RET_setting_location_accuracy, RET_setting_location_timeout, RET_GPSFailCount, RET_NetworkFailCount), sizeof(locString)); + } } int timetaken_gps = (RET_RTCunixtime - gpsStartTime); @@ -1095,7 +1136,7 @@ bool getSettings = true; //work out if we need to get settings back if ( ((RET_RTCunixtime - RET_SettingsGotAt)/3600) < RET_setting_minimumupdate_hrs ) { getSettings = false; timetaken_total -= 10;} //remove the extra 10 seconds from times - snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.0f,n:%.0f,q:%.0f,v:%.1f,z:L%s,e:%d,y:%d,x:%d,j:%d,s:%d%s)\0",GLOBAL_defaultApi,FW_VERSION,RET_temperature,RET_temperature_min,RET_temperature_max,RET_voltage,GLOBAL_exceptionString,timetaken_total,timetaken_connection,timetaken_gps,RET_motionStateOnInLocTXInterval,getSettings,locString); + snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.0f,n:%.0f,q:%.0f,w:%.0f,v:%.1f,z:L%s,e:%d,y:%d,x:%d,j:%d,s:%d%s)\0",GLOBAL_defaultApi,FW_VERSION,RET_temperature,RET_temperature_min,RET_temperature_max,RET_humidity,RET_voltage,GLOBAL_exceptionString,timetaken_total,timetaken_connection,timetaken_gps,RET_motionStateOnInLocTXInterval,getSettings,locString); //snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.0f,v:%.1f,z:L-%s,e:%d,y:%d,x:%d,j:%d,s:%d%s)\0",GLOBAL_defaultApi,FW_VERSION,RET_temperature,RET_voltage,GLOBAL_exceptionString,timetaken_total,timetaken_connection,timetaken_gps,RET_motionStateOnInLocTXInterval,getSettings,locString); char result[180]; snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytesToSend, getSettings, GLOBAL_defaultApi));