/* * data_processing.c * * Created on: Feb 3, 2023 * Author: Partha */ #include #include #include "nvs_flash.h" #include "esp_system.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include #include "sys/time.h" #include "driver/gpio.h" #include "esp_log.h" #include "math.h" #include "sdkconfig.h" #include "time.h" #include "rtc_wdt.h" #include "modem.h" #include "esp_mac.h" #include "uart_ifx.h" #include "esp_task_wdt.h" #include "port.h" #include "adc_ifx.h" <<<<<<< HEAD #include "ulp_main.h" #include "i2c_sensors.h" #include "data_processing.h" #include "ulp_main.h" ======= #include "data_processing.h" >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include "main.h" #include "hmi.h" #include "comms.h" #include "lwip/ip4_addr.h" #include "wifi_Init.h" #include "nvm.h" #include "wifi_OTA.h" static const char* TAG = "DATA"; #define LOG_LOCAL_LEVEL ESP_LOG_INFO #include "esp_log.h" #define IMEI "353165803930522" extern bool isCycleCompleted; extern uint8_t comms_mode; <<<<<<< HEAD extern comms_medium_t comms_medium; ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) extern uint8_t checkin_cycle_counter; extern uint8_t number_of_check_in_to_do; static char thermocouple_type; uint32_t g_version = 0; uint32_t g_wifiConnectTime; float g_voltage = 0; bool g_usbConnected = 0; bool g_enableButtonTiming; RTC_DATA_ATTR static bool g_prevUsbConnected; uint32_t light_mv = 0; uint8_t checkInAttemptNumber = 1; time_t g_wakeUpTime = 0; uint32_t g_StatusFlags = 0; uint32_t g_triggerFlags1 = 0; uint32_t g_triggerFlags2 = 0; // Configuration global variable uint32_t g_server_time = 0; uint32_t g_ID; uint32_t g_SensorInt; uint32_t g_ConfigUpdate; uint32_t g_McuUpdate; uint32_t g_ModemUpdate; <<<<<<< HEAD /*RTC_DATA_ATTR static uint16_t g_triggersThatCanWakeTheHost; RTC_DATA_ATTR static uint16_t g_strobedHumidityFlags; RTC_DATA_ATTR static uint16_t g_strobedMiscFlags; RTC_DATA_ATTR static uint16_t g_strobedMotionFlags; RTC_DATA_ATTR static uint16_t g_strobedTemperatureFlags; RTC_DATA_ATTR static uint16_t g_strobedThermocoupleFlags;*/ extern uint8_t wakeHostForStrobedTrigger2; extern void set_delay_sleep(void); typedef struct { uint8_t accel : 2; uint8_t vusb : 2; uint8_t lowv: 2; uint8_t pushbtn: 2; }isr_data_t; static isr_data_t isr_data; void IRAM_ATTR accel_int1_isr(void *args) { isr_data.accel = 1 + gpio_get_level(9); } void IRAM_ATTR vusb_detect_isr(void *args) { isr_data.vusb = 1 + gpio_get_level(10); } void IRAM_ATTR lowv_detect_isr(void *args) { isr_data.lowv = 1 + gpio_get_level(38); } void IRAM_ATTR push_button_isr(void *args) { isr_data.pushbtn = 1 + gpio_get_level(5); } char urlConnect[70]={0}; static int32_t postToServer=1; static bool isTempPresent = false; static bool isAccelPresent = false; static bool isThermocouplePresent = false; typedef struct { //Sensor Data uint8_t thermocoupleMode; uint8_t thermocoupleType; uint8_t lightSensorMode; uint8_t accelerometerMode; uint8_t accelerometerInterval; uint8_t accelerometerLockoutInSeconds; uint8_t powerMonitorMode; uint8_t powerMonitorDebounceInSeconds; //uint8_t lightSensorLevelGP; //uint8_t lightSensorLevelGN; //lightTh uint8_t lightSensorLevel; // OTHERS uint8_t historyIndex; uint8_t numberOfHistoryLogEntriesUntilRetriesAreNotAllowed; bool sendDetails; uint16_t lightSensorLockoutInSeconds; //acclTh uint16_t accelerometerLevel; // INTERVALS uint32_t sendInterval; uint32_t alertInterval; //Limits int32_t minHum; int32_t maxHum; // DYNAMIC VARS int32_t postURLNumber; int32_t postURLMax; // Highest URL to try //Limits float minTemp; float maxTemp; float voltageQuit; //limits Tc float maxTcTemp; float minTcTemp; //limits probe float maxProbeTemp; float minProbeTemp; }settings; settings *esp_settings = (settings*)(&ulp_settings_structure); RTC_DATA_ATTR historyLog_t _logs[NVM_MAX_NUMBER_OF_IN_ONE_SECTOR] = {}; ======= RTC_DATA_ATTR historyLog_t _logs[NVM_MAX_NUMBER_OF_IN_ONE_SECTOR] = {}; >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) typedef struct { // Stored in RTC RAM during Deep Sleeps. This reduces wear on the FLASH. // TIMING uint32_t timeOfLastRadioCalibration; uint32_t checkInClock; uint32_t retry1Clock; uint32_t retry2Clock; int8_t lteRssi; // Modem signal strength // WIFI CONFIG uint8_t bssid[6]; esp_netif_ip_info_t localIp; esp_netif_dns_info_t dns1; esp_netif_dns_info_t dns2; uint8_t wifiChannel; int32_t wifi_rssi; // OTHERS uint32_t operatingMode; uint32_t initializationVector[4]; bool initializationVectorCreated; uint32_t checkInCount; float temperatureAtLastRadioCalibration; bool retriesAreInProgress; }rtcRamData_t; RTC_DATA_ATTR rtcRamData_t _rtcRamData; <<<<<<< HEAD uint32_t data_get_send_interval(void) { if(esp_settings->sendInterval) return esp_settings->sendInterval; else return 900; } bool data_is_usb_connected(void) { return g_usbConnected; } ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static esp_err_t data_parse_float_value(float *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; char parse_value[] = {'0'}; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 1; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)",") + 1; if((char *)1 == end_add) end_add = start_add + strlen(start_add) + 1; /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(parse_value, len, "%s", start_add); /*6- Assign the double value to the target buffer*/ *target_buffer = atof(parse_value); retval = ESP_OK; } return retval; } static esp_err_t data_parse_int_value(int32_t *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; char parse_value[] = {'0'}; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 1; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)",") + 1; if((char *)1 == end_add) end_add = start_add + strlen(start_add) + 1; /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(parse_value, len, "%s", start_add); /*6- Assign the double value to the target buffer*/ *target_buffer = atoi(parse_value); retval = ESP_OK; } return retval; } static esp_err_t data_parse_uint8_value(uint8_t *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; char parse_value[] = {'0'}; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 1; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)",") + 1; if((char *)1 == end_add) end_add = start_add + strlen(start_add) + 1; /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(parse_value, len, "%s", start_add); /*6- Assign the double value to the target buffer*/ *target_buffer = atoi(parse_value); retval = ESP_OK; } return retval; } static esp_err_t data_parse_uint16_value(uint16_t *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; char parse_value[] = {'0'}; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 1; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)",") + 1; if((char *)1 == end_add) end_add = start_add + strlen(start_add) + 1; /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(parse_value, len, "%s", start_add); /*6- Assign the double value to the target buffer*/ *target_buffer = atoi(parse_value); retval = ESP_OK; } return retval; } static esp_err_t data_parse_uint_value(uint32_t *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; char parse_value[] = {'0'}; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 1; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)",") + 1; if((char *)1 == end_add) end_add = start_add + strlen(start_add) + 1; /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(parse_value, len, "%s", start_add); /*6- Assign the double value to the target buffer*/ *target_buffer = atoi(parse_value); retval = ESP_OK; } return retval; } static esp_err_t data_parse_String_value(char *target_buffer, const char needle[], const char *http_resp) { esp_err_t retval = ESP_FAIL; char *ret = NULL; char *start_add = NULL; char *end_add = NULL; int len = 0; /*1- Extract temperature limits*/ ret = strstr(http_resp, needle); if(ret) { /*2- get the starting address of the value*/ start_add = strstr(ret,(char*)":") + 2; /*3- get the ending address of the value*/ end_add = strstr(ret,(char*)","); /*4- Calculate the length of the value*/ len = end_add - start_add; /*5- copy the value into the buffer*/ snprintf(target_buffer, len, "%s", start_add); retval = ESP_OK; } return retval; } <<<<<<< HEAD static void setAccelerometerPowerState(void) { switch(esp_settings->accelerometerMode) { case 0: // Disable accelerometer if(ESP_FAIL == i2c_set_mc3419_mode(MC3419_STANDBY_MODE)) // Only mode register can be written in WAKE mode. All other registers are read-only. It appears that clearing the interrupt flags is an exception to this rule. ESP_LOGI(TAG,"Accelerometer error #6."); if(ESP_FAIL == i2c_clear_mc3419_int_flag()) ESP_LOGI(TAG,"Accelerometer error #4."); break; case 1: // "Bumping" motion detection. if(ESP_FAIL == i2c_set_mc3419_mode(MC3419_WAKE_MODE)) // Only mode register can be written in WAKE mode. All other registers are read-only. It appears that clearing the interrupt flags is an exception to this rule. ESP_LOGI(TAG,"Accelerometer error #5."); else ESP_LOGI(TAG,"Accelerometer mode now is WAKEUP mode.\n Accelerometer is ready to receive Interrupts"); if(ESP_FAIL == i2c_clear_mc3419_int_flag()) ESP_LOGI(TAG,"Accelerometer error #4."); break; default: // All other yet-to-be-implemented modes. ESP_LOGI(TAG,"Setting Accelerometer mode to be STANDBY Mode"); if(ESP_FAIL == i2c_set_mc3419_mode(MC3419_STANDBY_MODE)) // Only mode register can be written in WAKE mode. All other registers are read-only. It appears that clearing the interrupt flags is an exception to this rule. ESP_LOGI(TAG,"Accelerometer error #6."); if(ESP_FAIL == i2c_clear_mc3419_int_flag()) ESP_LOGI(TAG,"Accelerometer error #4."); break; } } static void data_clear_sensor_strobes(uint16_t tempFlags, uint16_t humiFlags, uint16_t thermocoupleFlags, uint16_t motionFlags, uint16_t miscFlags) { ulp_ulp_strobedTemperatureFlags &= ~tempFlags; // Clear the masked strobed interrupt flags. ulp_ulp_strobedHumidityFlags &= ~humiFlags; // Clear the masked strobed interrupt flags. ulp_ulp_strobedThermocoupleFlags &= ~thermocoupleFlags; // Clear the masked strobed interrupt flags. ulp_ulp_strobedMiscFlags &= ~miscFlags; // Clear the masked strobed interrupt flags. ulp_ulp_strobedMotionFlags &= ~motionFlags; // Clear the masked strobed interrupt flags. } static void data_parse_limits(const char *http_resp) { //parse the value of minTemp data_parse_float_value(&(esp_settings->minTemp), "minTemp", http_resp); ESP_LOGI(TAG,"minTemp = %f",esp_settings->minTemp); ulp_temperature_raw_min_thr = (uint32_t)(esp_settings->minTemp+273.15)*64; //parse the value of maxTemp data_parse_float_value(&(esp_settings->maxTemp), "maxTemp", http_resp); ESP_LOGI(TAG,"maxTemp = %f",esp_settings->maxTemp); ulp_temperature_raw_max_thr = (uint32_t)(esp_settings->maxTemp+273.15)*64; //parse the value of minHum data_parse_int_value(&(esp_settings->minHum), "minHum", http_resp); ESP_LOGI(TAG,"minHum = %ld",esp_settings->minHum); ulp_humidity_raw_min_thr = (uint32_t)esp_settings->minHum*512; //parse the value of maxHum data_parse_int_value(&(esp_settings->maxHum), "maxHum", http_resp); ESP_LOGI(TAG,"maxHum = %ld",esp_settings->maxHum); ulp_humidity_raw_max_thr = (uint32_t)esp_settings->maxHum*512; //parse the value of voltageQuit data_parse_float_value(&(esp_settings->voltageQuit), "voltageQuit", http_resp); ESP_LOGI(TAG,"voltageQuit = %f",esp_settings->voltageQuit); } static void data_parse_intervals(const char *http_resp) { //uint32_t prevSendInterval = esp_settings->sendInterval; uint8_t prev_commsMode = comms_mode; //Parse server time data_parse_uint_value(&g_server_time, "time", http_resp); if(g_server_time) { struct timeval tv; tv.tv_sec = g_server_time; settimeofday(&tv, NULL); } //parse the value of alertInterval data_parse_uint_value(&(esp_settings->alertInterval), "alertInterval", http_resp); ESP_LOGI(TAG,"alertInterval = %ld",esp_settings->alertInterval); //parse the value of sendInterval data_parse_uint_value(&(esp_settings->sendInterval), "sendInterval", http_resp); ESP_LOGI(TAG,"sendInterval = %ld",esp_settings->sendInterval); //parse the value of commsMode data_parse_uint8_value(&(comms_mode), "commsMode", http_resp); /* Make sure that the comms-mode is between 1 and 5 and not equal to the old comms-mode (to save the life of NVS) */ if((comms_mode > 0) && (comms_mode < 5) && (prev_commsMode != comms_mode)) { /* Store the COMMS-Mode in NVS */ nvm_write_comms_mode(comms_mode); ESP_LOGI(TAG,"commsMode = %d",comms_mode); } else { comms_mode = prev_commsMode; } // update checkin timer period, only if time period has changed. //if(prevSendInterval != esp_settings->sendInterval) { update_checkin_timer((uint64_t)esp_settings->sendInterval); } } static void data_parse_dynamicVariables(const char *http_resp) { /* parse the value of sendDetails*/ uint32_t sendDetails = 0; data_parse_uint_value(&(sendDetails), "sendDetails", http_resp); if(sendDetails == 1) { esp_settings->sendDetails = true; ESP_LOGI(TAG,"sendDetails = true"); } else { esp_settings->sendDetails = false; ESP_LOGI(TAG,"sendDetails = false"); } /* parse the value of postURLNumber*/ data_parse_int_value(&(esp_settings->postURLNumber), "postURLNumber", http_resp); ESP_LOGI(TAG,"postURLNumber = %ld",esp_settings->postURLNumber); /* parse the value of postURLMax*/ data_parse_int_value(&(esp_settings->postURLMax), "postURLMax", http_resp); ESP_LOGI(TAG,"postURLMax = %ld",esp_settings->postURLMax); } static void data_parse_temperature(const char *http_resp) { #if 0 /*Temperature Thresholds/Tokens:*/ /* parse the value of tmpThA_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdA_GP), "tmpThA_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdA_GP = %f",esp_settings->temperatureThresholds.thresholdA_GP); /* parse the value of tmpThA_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdA_GN), "tmpThA_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdA_GN = %f",esp_settings->temperatureThresholds.thresholdA_GN); /* parse the value of tmpThB_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdB_GP), "tmpThB_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdB_GP = %f",esp_settings->temperatureThresholds.thresholdB_GP); /* parse the value of tmpThB_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdB_GN), "tmpThB_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdB_GN = %f",esp_settings->temperatureThresholds.thresholdB_GN); /* parse the value of tmpThC_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdC_GP), "tmpThC_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdC_GP = %f",esp_settings->temperatureThresholds.thresholdC_GP); /* parse the value of tmpThC_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdC_GN), "tmpThC_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdC_GN = %f",esp_settings->temperatureThresholds.thresholdC_GN); /* parse the value of tmpThD_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdD_GP), "tmpThD_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdD_GP = %f",esp_settings->temperatureThresholds.thresholdD_GP); /* parse the value of tmpThD_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdD_GN), "tmpThD_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdD_GN = %f",esp_settings->temperatureThresholds.thresholdD_GN); /* parse the value of tmpThE_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdE_GP), "tmpThE_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdE_GP = %f",esp_settings->temperatureThresholds.thresholdE_GP); /* parse the value of tmpThE_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdE_GN), "tmpThE_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdE_GN = %f",esp_settings->temperatureThresholds.thresholdE_GN); /* parse the value of tmpThF_GP*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdF_GP), "tmpThF_GP", http_resp); ESP_LOGI(TAG,"Temp_thresholdF_GP = %f",esp_settings->temperatureThresholds.thresholdF_GP); /* parse the value of tmpThF_GN*/ data_parse_float_value(&(esp_settings->temperatureThresholds.thresholdF_GN), "tmpThF_GN", http_resp); ESP_LOGI(TAG,"Temp_thresholdF_GN = %f",esp_settings->temperatureThresholds.thresholdF_GN); /* parse the value of T_TKN*/ data_parse_uint8_value(&(esp_settings->temperatureTokens), "T_TKN", http_resp); ESP_LOGI(TAG,"Temperature Tokens = %d",esp_settings->temperatureTokens); #endif } static void data_parse_humidity(const char *http_resp) { #if 0 /*Humidity Thresholds/Tokens:*/ /* parse the value of humThA_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdA_GP), "humThA_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdA_GP = %f",esp_settings->humidityThresholds.thresholdA_GP); /* parse the value of humThA_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdA_GN), "humThA_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdA_GN = %f",esp_settings->humidityThresholds.thresholdA_GN); /* parse the value of humThB_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdB_GP), "humThB_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdB_GP = %f",esp_settings->humidityThresholds.thresholdB_GP); /* parse the value of humThB_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdB_GN), "humThB_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdB_GN = %f",esp_settings->humidityThresholds.thresholdB_GN); /* parse the value of humThC_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdC_GP), "humThC_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdC_GP = %f",esp_settings->humidityThresholds.thresholdC_GP); /* parse the value of humThC_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdC_GN), "humThC_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdC_GN = %f",esp_settings->humidityThresholds.thresholdC_GN); /* parse the value of humThD_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdD_GP), "humThD_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdD_GP = %f",esp_settings->humidityThresholds.thresholdD_GP); /* parse the value of humThD_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdD_GN), "humThD_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdD_GN = %f",esp_settings->humidityThresholds.thresholdD_GN); /* parse the value of humThE_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdE_GP), "humThE_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdE_GP = %f",esp_settings->humidityThresholds.thresholdE_GP); /* parse the value of humThE_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdE_GN), "humThE_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdE_GN = %f",esp_settings->humidityThresholds.thresholdE_GN); /* parse the value of humThF_GP*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdF_GP), "humThF_GP", http_resp); ESP_LOGI(TAG,"Humi_thresholdF_GP = %f",esp_settings->humidityThresholds.thresholdF_GP); /* parse the value of humThF_GN*/ data_parse_float_value(&(esp_settings->humidityThresholds.thresholdF_GN), "humThF_GN", http_resp); ESP_LOGI(TAG,"Humi_thresholdF_GN = %f",esp_settings->humidityThresholds.thresholdF_GN); /* parse the value of H_TKN*/ data_parse_uint8_value(&(esp_settings->humidityTokens), "H_TKN", http_resp); ESP_LOGI(TAG,"Humi_tokens = %d",esp_settings->humidityTokens); #endif } static void data_parse_thermocouple(const char *http_resp) { int32_t *x = (int32_t*)&ulp_thermo_raw_min_thr; /*Thermocouple Thresholds/Tokens/mode:*/ /* parse the value of tcTh*/ data_parse_float_value(&(esp_settings->maxTcTemp), "maxTcTemp", http_resp); if(esp_settings->maxTcTemp == 0) { esp_settings->maxTcTemp = 50; } ESP_LOGI(TAG,"max thermocoupleThreshold = %f",esp_settings->maxTcTemp); ulp_thermo_raw_max_thr = esp_settings->maxTcTemp; //ulp_thermo_raw_max_thr = esp_settings->maxTcTemp*16; /* parse the value of tcTh*/ data_parse_float_value(&(esp_settings->minTcTemp), "minTcTemp", http_resp); if(esp_settings->minTcTemp == 0) { esp_settings->minTcTemp = -100; } ESP_LOGI(TAG,"min thermocoupleThreshold = %f",esp_settings->minTcTemp); *x = (int32_t)esp_settings->minTcTemp; /*ulp_thermo_raw_min_thr = (esp_settings->minTcTemp+4096); ulp_thermo_raw_min_thr |= 0x8000; ulp_thermo_raw_min_thr *= 16;*/ #if 0 /* parse the value of tcThA_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdA_GP), "tcThA_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdA_GP = %f",esp_settings->thermocoupleThresholds.thresholdA_GP); /* parse the value of tcThA_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdA_GN), "tcThA_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdA_GN = %f",esp_settings->thermocoupleThresholds.thresholdA_GN); /* parse the value of tcThB_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdB_GP), "tcThB_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdB_GP = %f",esp_settings->thermocoupleThresholds.thresholdB_GP); /* parse the value of tcThB_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdB_GN), "tcThB_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdB_GN = %f",esp_settings->thermocoupleThresholds.thresholdB_GN); /* parse the value of tcThC_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdC_GP), "tcThC_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdC_GP = %f",esp_settings->thermocoupleThresholds.thresholdC_GP); /* parse the value of tcThC_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdC_GN), "tcThC_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdC_GN = %f",esp_settings->thermocoupleThresholds.thresholdC_GN); /* parse the value of tcThD_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdD_GP), "tcThD_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdD_GP = %f",esp_settings->thermocoupleThresholds.thresholdD_GP); /* parse the value of tcThD_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdD_GN), "tcThD_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdD_GN = %f",esp_settings->thermocoupleThresholds.thresholdD_GN); /* parse the value of tcThE_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdE_GP), "tcThE_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdE_GP = %f",esp_settings->thermocoupleThresholds.thresholdE_GP); /* parse the value of tcThE_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdE_GN), "tcThE_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdE_GN = %f",esp_settings->thermocoupleThresholds.thresholdE_GN); /* parse the value of tcThF_GP*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdF_GP), "tcThF_GP", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdF_GP = %f",esp_settings->thermocoupleThresholds.thresholdF_GP); /* parse the value of tcThF_GN*/ data_parse_float_value(&(esp_settings->thermocoupleThresholds.thresholdF_GN), "tcThF_GN", http_resp); ESP_LOGI(TAG,"thermocoupleThresholds.thresholdF_GN = %f",esp_settings->thermocoupleThresholds.thresholdF_GN); /* parse the value of TC_TKN*/ data_parse_uint8_value(&(esp_settings->thermocoupleTokens), "TC_TKN", http_resp); ESP_LOGI(TAG,"thermocoupleTokens = %d",esp_settings->thermocoupleTokens); #endif /* parse the value of TC_M*/ data_parse_String_value((char*)&(thermocouple_type), "TC_TYPE", http_resp); switch(thermocouple_type) { case 'K': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_K; break; case 'J': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_J; break; case 'T': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_T; break; case 'N': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_N; break; case 'S': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_S; break; case 'E': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_E; break; case 'B': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_B; break; case 'R': esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_R; break; default: esp_settings->thermocoupleType = THERMOCOUPLE_TYPE_K; break; } ESP_LOGI(TAG,"thermocoupleType = %c",thermocouple_type); ESP_LOGI(TAG,"thermocoupleType = %d",esp_settings->thermocoupleType); /*Setting thermocouple type in the MCP9600 module*/ i2c_mcp9600_set_type(esp_settings->thermocoupleType); /* parse the value of TC_M*/ data_parse_uint8_value(&(esp_settings->thermocoupleMode), "TC_M", http_resp); ESP_LOGI(TAG,"thermocoupleMode = %d",esp_settings->thermocoupleMode); /*Process thermocouple mode*/ data_processSensorModes(THERMOCOUPLE_SENSOR); } #if 0 uint32_t data_get_light_sensor_gp(void) { if(esp_settings->lightSensorLevelGP == 0) return 200; return esp_settings->lightSensorLevelGP; } uint32_t data_get_light_sensor_gn(void) { if(esp_settings->lightSensorLevelGN == 0) return 50; return esp_settings->lightSensorLevelGN; } #endif uint8_t data_get_light_sensor_threshold(void) { if(esp_settings->lightSensorLevel == 0) return 130; return esp_settings->lightSensorLevel; } static void data_parse_lightSensor(const char *http_resp) { /* parse the value of LT_M*/ data_parse_uint8_value(&(esp_settings->lightSensorMode), "LT_M", http_resp); ESP_LOGI(TAG,"lightSensorMode = %d",esp_settings->lightSensorMode); #if 0 /* parse the value of LT_LVLGP*/ data_parse_uint8_value(&(esp_settings->lightSensorLevelGP), "LT_LVLGP", http_resp); ESP_LOGI(TAG,"lightSensorLevelGP = %d",esp_settings->lightSensorLevelGP); /* parse the value of LT_LVLGN*/ data_parse_uint8_value(&(esp_settings->lightSensorLevelGN), "LT_LVLGN", http_resp); ESP_LOGI(TAG,"lightSensorLevelGN = %d",esp_settings->lightSensorLevelGN); #endif /* parse the value of LT_LVL*/ data_parse_uint8_value(&(esp_settings->lightSensorLevel), "lightTh", http_resp); ESP_LOGI(TAG,"lightSensorLevel = %d",esp_settings->lightSensorLevel); /* parse the value of LT_LOCK*/ data_parse_uint16_value(&(esp_settings->lightSensorLockoutInSeconds), "LT_LOCK", http_resp); ESP_LOGI(TAG,"lightSensorLockoutInSeconds = %d",esp_settings->lightSensorLockoutInSeconds); /* parse the value of LT_TKN*/ //data_parse_uint8_value(&(esp_settings->lightSensorTokens), "LT_TKN", http_resp); //ESP_LOGI(TAG,"lightSensorTokens = %d",esp_settings->lightSensorTokens); /*Process light_sensor mode*/ data_processSensorModes(LIGHT_SENSOR); } static void data_parse_accelerometer(const char *http_resp) { /* Enabling power to accelerometer to set the new motion-detection level*/ port_accel_pwr_enable(1); /* Wait some time till the sensor get powered on*/ vTaskDelay(100/portTICK_PERIOD_MS); /* parse the value of AC_M*/ data_parse_uint8_value(&(esp_settings->accelerometerMode), "AC_M", http_resp); ESP_LOGI(TAG,"accelerometerMode = %d",esp_settings->accelerometerMode); /* parse the value of AC_LVL*/ data_parse_uint16_value(&(esp_settings->accelerometerLevel), "AC_LVL", http_resp); ESP_LOGI(TAG,"accelerometerLevel = %d",esp_settings->accelerometerLevel); /* parse the value of AC_INT*/ data_parse_uint8_value(&(esp_settings->accelerometerInterval), "AC_INT", http_resp); ESP_LOGI(TAG,"accelerometerInterval = %d",esp_settings->accelerometerInterval); /* parse the value of AC_LOCK*/ data_parse_uint8_value(&(esp_settings->accelerometerLockoutInSeconds), "AC_LOCK", http_resp); ESP_LOGI(TAG,"accelerometerLockoutInSeconds = %d",esp_settings->accelerometerLockoutInSeconds); /* parse the value of AC_TKN*/ //data_parse_uint8_value(&(esp_settings->accelerometerTokens), "AC_TKN", http_resp); //ESP_LOGI(TAG,"accelerometerTokens = %d",esp_settings->accelerometerTokens); /*Process accelerometer mode*/ data_processSensorModes(ACCELEROMETER_SENSOR); /*Set Accelerometer motion-detection level*/ //i2c_set_mc3419_motionThreshold(esp_settings->accelerometerLevel); //ESP_LOGI(TAG,"The new motion_detection threshold %d has been set",esp_settings->accelerometerLevel); /* Disabling accelerometer power*/ //port_accel_pwr_enable(0); } static void data_parse_power(const char *http_resp) { /* parse the value of PWR_M*/ data_parse_uint8_value(&(esp_settings->powerMonitorMode), "PWR_M", http_resp); ESP_LOGI(TAG,"powerMonitorMode = %d",esp_settings->powerMonitorMode); /* parse the value of PWR_DBNC*/ data_parse_uint8_value(&(esp_settings->powerMonitorDebounceInSeconds), "PWR_DBNC", http_resp); ESP_LOGI(TAG,"powerMonitorDebounceInSeconds = %d",esp_settings->powerMonitorDebounceInSeconds); /* parse the value of PWR_TKN*/ //data_parse_uint8_value(&(esp_settings->powerMonitorTokens), "PWR_TKN", http_resp); //ESP_LOGI(TAG,"powerMonitorTokens = %d",esp_settings->powerMonitorTokens); /*Process power_monitor mode*/ data_processSensorModes(POWER_MONITOR_SENSOR); } static void data_parse_pushbutton(const char *http_resp) { /* parse the value of PUSH_TKN*/ //data_parse_uint8_value(&(esp_settings->pushbuttonTokens), "PUSH_TKN", http_resp); //ESP_LOGI(TAG,"pushbuttonTokens = %d",esp_settings->pushbuttonTokens); /* parse the value of TKN_RLD*/ //data_parse_uint16_value(&(esp_settings->tokenReloadIntervalInSeconds), "TKN_RLD", http_resp); //ESP_LOGI(TAG,"tokenReloadIntervalInSeconds = %d",esp_settings->tokenReloadIntervalInSeconds); } uint16_t data_get_motion_threshold(void) { if(0 == esp_settings->accelerometerLevel) return 1000; return esp_settings->accelerometerLevel; } bool data_setTempPresent(bool status) { isTempPresent = status; return status; } bool data_setAccelPresent(bool status) { isAccelPresent = status; return status; } bool data_setThermocouplePresent(bool status) { isThermocouplePresent = status; return status; } void data_set_accel_int1_wakeup(void) { isr_data.accel = 2; } void data_set_pushbutton_int0_wakeup(void) { isr_data.pushbtn = 1; } void data_set_vusb_init_interrupt(void) { isr_data.vusb = 1 + gpio_get_level(10); } batteryChargingState_t detect_if_usb_is_charging(void) { static int counter = 0; static int usb_state; static int prev_usb_state; static int is_first; static int transition; static int high_low; static int low_high; static int always_low = 0; static int always_high = 0; static bool always_state_set = false; batteryChargingState_t battery_charging_state = BATTERY_CHARGED; /*Read charging status pin up to 20 readings*/ if(g_usbConnected == 1) { /*Reading the state of USB-Charging pin*/ usb_state = port_is_charging(); //ESP_LOGI(TAG,"USB current state = %d and previous state = %d",usb_state,prev_usb_state); if(usb_state == 0) { always_low++; // 11 always_high = 0; } else { always_high++; always_low = 0; } /*Assuming prev_usb_state is the same as usb_state just for the first reading*/ if(!is_first) { is_first = 1; prev_usb_state = usb_state; } /*Check if there is a transition*/ if(prev_usb_state != usb_state) { always_state_set = false; hmi_set_leds_state(BLUE_RED_LEDS_USB_OFF); //ESP_LOGI(TAG,"USB current state = %d and previous state = %d",usb_state,prev_usb_state); counter = 0; transition = 1; low_high = high_low = 0; /*Detect the edge of that transition*/ if(prev_usb_state > usb_state) { high_low = 1; } else { low_high = 1; } prev_usb_state = usb_state; } if(transition) counter++; if(counter > 10) { if(high_low) { counter = 0; transition = 0; battery_charging_state = BATTERY_CHARGING; } else if(low_high) { counter = 0; transition = 0; battery_charging_state = BATTERY_CHARGED; } low_high = high_low = 0; } else { if(always_low >= 10) { battery_charging_state = BATTERY_CHARGING; always_low--; if(!always_state_set) { always_state_set = true; ESP_LOGI(TAG,"#### BATTERY is charging ######"); hmi_set_leds_state(BLUE_RED_LEDS_FLASHING_1SEC); } } else if(always_high >= 10) { battery_charging_state = BATTERY_CHARGED; always_high--; if(!always_state_set) { ESP_LOGI(TAG,"#### BATTERY is charged #######"); always_state_set = true; hmi_set_leds_state(BLUE_RED_LEDS_SOLD); } } } } return battery_charging_state; } void data_check_button_holding_time(void) { static uint16_t button_pressed_time; int button_state = 5; /* 1. Check whether the USB is connected or not */ if(g_usbConnected) { /*2. Read button state */ button_state = port_is_pushbuttonNotPressed(); //pressed ---> 0 not_pressed ---> 1 /*3. Check the button state*/ if(!button_state) { /*3.1. If pressed then increased the button_pressed_time by 100ms */ button_pressed_time += 100; } else { /*3.2. If released then reset the button_pressed_time to 0 and end the function*/ button_pressed_time = 0; /*3.3. Stop button_timing*/ g_enableButtonTiming = 0; /*4.3. Exit the function*/ return; } /*4. Check whether the button_pressed_time is >= 10 seconds (10000ms) */ if(button_pressed_time >= 10000) { /* 4.1. Reset button_pressed_time */ button_pressed_time = 0; /* 4.2. Erase the NVS storage */ ESP_ERROR_CHECK(nvs_flash_erase()); /* 4.3. Reset the device (Software reset) */ esp_restart(); } } else { /* If USB is not connected then reset button_pressed_time to 0 */ button_pressed_time = 0; /* and button_timing */ g_enableButtonTiming = false; } } void data_task(void *pvParameters) { batteryChargingState_t charging_state; for(;;) { /*Check the State of USB and battery (is the battery charging or fully charged) to set the corresponding LED event */ charging_state = detect_if_usb_is_charging(); /* Check the state of ButtonTiming and USB */ if(g_enableButtonTiming) data_check_button_holding_time(); //If buttonTiming is enabled then start button_timing /* Check if the accelerometer isr_flag has been set by its isr_handler */ if(isr_data.accel) { /* Log the state of the accelerometer INT1 pin*/ ESP_LOGI(TAG, "ACCEL INT1 %s", (isr_data.accel == 2)?"HIGH":"LOW"); /* Was the accelerometer INT1 pin High ?*/ if(isr_data.accel == 2) { /* Clear the interrupt flag*/ i2c_clear_mc3419_int_flag(); /* Set the motion detection strobe*/ if(ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_ON_MOVEMENT_DETECTION) { ulp_ulp_strobedMotionFlags |= STROBED_MOTION_MOVEMENT_DETECTED; // Rise a trigger flag to do the check-in process before going to deep-sleep wakeHostForStrobedTrigger2++; /* Check if the device-last cycle is completed and the device now is in pausing period*/ if(isCycleCompleted) { #if (SENS_INT_WAKEUP == 0) //set_sleep_mode(); set_delay_sleep(); #else //set_periodic_sleep_mode(); set_delay_sleep(); //If yes then ----> trigger the check-in process(set the sensorNeeded flag to enable sensor_task) #endif } /* Reduce the accelerometer tokens by 1*/ //if(esp_settings->accelerometerTokens) //esp_settings->accelerometerTokens--; } } /* Reset the isr flag */ isr_data.accel = 0; } /* Check if the VUSB isr_flag has been set by its isr_handler */ if(isr_data.vusb) { /* Log the state of the USB */ ESP_LOGI(TAG, "VUSB %s", (isr_data.vusb == 2)?"CONNECTED":"DISCONNECTED"); /* did the USB get connected ?*/ if(isr_data.vusb == 2) { /* Update the previous state of USB*/ g_prevUsbConnected = g_usbConnected; /* Set the new state of USB to be true (connected) */ g_usbConnected = 1; /* Set the usb_connection_flag in HMI */ hmi_set_usb_connection_state(true); /* Process the the current and previous states of USB if the power_mode is enabled */ data_process_power_thresholds(); /* Check the state battery charging to set the corresponding LED-Event in the HMI */ if(charging_state == BATTERY_CHARGING) hmi_set_leds_state(BLUE_RED_LEDS_FLASHING_1SEC); else if(charging_state == BATTERY_CHARGED) hmi_set_leds_state(BLUE_RED_LEDS_SOLD); } /* did the USB get disconnected ?*/ else if(isr_data.vusb == 1) { /* Update the previous state of USB*/ g_prevUsbConnected = g_usbConnected; /* Set the new state of USB to be false (disconnected) */ g_usbConnected = 0; /* Process the the current and previous states of USB if the power_mode is enabled */ data_process_power_thresholds(); /* Reset the usb_connection_flag in HMI */ hmi_set_usb_connection_state(false); //hmi_set_leds_state(BLUE_RED_LEDS_OFF); } /*Check if we should trigger check-in process when connecting and disconnecting USB*/ if(ulp_ulp_triggersThatCanWakeTheHost & (WAKE_HOST_ON_SWITCH_FROM_BATTERY_TO_USB | WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY)) { /* Check if the device-last cycle is completed and the device now is in pausing period*/ if(isCycleCompleted) { #if (SENS_INT_WAKEUP == 0) //set_sleep_mode(); set_delay_sleep(); #else //set_periodic_sleep_mode(); set_delay_sleep(); //If yes then ----> trigger the check-in process(set the sensorNeeded flag to enable sensor_task) #endif } } isr_data.vusb = 0; } if(isr_data.lowv == 2) { ESP_LOGI(TAG, "LOW VOLTAGE"); isr_data.lowv = 0; } /* Check if the PushButton isr_flag has been set by its isr_handler */ if(isr_data.pushbtn) { /* did the pushbutton get pressed ?*/ if(isr_data.pushbtn == 1) { /* Log the state of the button (pressed) */ ESP_LOGI(TAG, "BUTTON PRESSED"); /* Enable Button_timing to start timing for button_pressed period*/ g_enableButtonTiming = true; //update the strobe of the check_in and reduce pushbuttonTokens ulp_ulp_strobedMiscFlags |= STROBED_MISC_CHECK_IN_REQUESTED; // Rise a trigger flag to do the check-in process before going to deep-sleep wakeHostForStrobedTrigger2++; /* if(esp_settings->pushbuttonTokens) { esp_settings->pushbuttonTokens--; wakeHostForStrobedTrigger2++; }*/ //only when button press enabled (checking device is on and working properly) //port_blue_led_on(); hmi_set_leds_state(BLUE_LED_SOLID); /* Check if the device-last cycle is completed and the device now is in pausing period*/ if(isCycleCompleted) { #if (SENS_INT_WAKEUP == 0) //set_sleep_mode(); set_delay_sleep(); #else //set_periodic_sleep_mode(); set_delay_sleep(); //If yes then ----> trigger the check-in process(set the sensorNeeded flag to enable sensor_task) #endif } } else if(isr_data.pushbtn == 2) { /**/ } isr_data.pushbtn = 0; } vTaskDelay(100 / portTICK_PERIOD_MS); } vTaskDelete(NULL); } /***************** ***************Buffer Example (json format)****************************************/ static uint32_t data_get_history_field_uint_values(uint8_t index, historyLog_field_t field) { switch(field) { case HISTORY_TEMP_FIELD: break; case HISTORY_HUMI_FIELD: break; case HISTORY_THERM_FIELD: break; case HISTORY_LIGHT_FIELD: return (uint32_t)_logs[index].logLight; case HISTORY_TIME_FIELD: return (uint32_t)_logs[index].logCheckInTime; case HISTORY_TRIG1_FIELD: return (uint32_t)_logs[index].logTriggerFlags1; case HISTORY_TRIG2_FIELD: return (uint32_t)_logs[index].logTriggerFlags2; case HISTORY_XAXIS_FIELD: return (uint32_t)_logs[index].logXaxis; case HISTORY_YAXIS_FIELD: return (uint32_t)_logs[index].logYaxis; case HISTORY_ZAXIS_FIELD: return (uint32_t)_logs[index].logZaxis; case HISTORY_RSSI_FIELD: break; case HISTORY_STAUS_FIELD: return (uint32_t)_logs[index].logStatusFlags; case HISTORY_RECORD_FIELD: break; } return 0; } #if 0 static int32_t data_get_history_field_int_values(uint8_t index, historyLog_field_t field) { switch(field) { case HISTORY_TEMP_FIELD: break; case HISTORY_HUMI_FIELD: break; case HISTORY_THERM_FIELD: break; case HISTORY_LIGHT_FIELD: break; case HISTORY_TIME_FIELD: break; case HISTORY_TRIG1_FIELD: break; case HISTORY_TRIG2_FIELD: break; case HISTORY_XAXIS_FIELD: return (int32_t)_logs[index].logXaxis; case HISTORY_YAXIS_FIELD: return (int32_t)_logs[index].logYaxis; case HISTORY_ZAXIS_FIELD: return (int32_t)_logs[index].logZaxis; case HISTORY_RSSI_FIELD: return (int32_t)_logs[index].logRSSI; case HISTORY_STAUS_FIELD: break; case HISTORY_RECORD_FIELD: return (int32_t)_logs[index].logHistoryRecorded; } return 0; } #endif static float data_get_history_field_float_values(uint8_t index, historyLog_field_t field) { switch(field) { case HISTORY_TEMP_FIELD: return _logs[index].logTemp; case HISTORY_HUMI_FIELD: return _logs[index].logHumidity; case HISTORY_THERM_FIELD: return _logs[index].logThermocoupleTemp; case HISTORY_LIGHT_FIELD: break; case HISTORY_TIME_FIELD: break; case HISTORY_TRIG1_FIELD: break; case HISTORY_TRIG2_FIELD: break; case HISTORY_XAXIS_FIELD: break; case HISTORY_YAXIS_FIELD: break; case HISTORY_ZAXIS_FIELD: break; case HISTORY_RSSI_FIELD: break; case HISTORY_STAUS_FIELD: break; case HISTORY_RECORD_FIELD: break; } return 0; } static size_t data_add_float_history_to_buf(char* buff, uint32_t len, size_t n, historyLog_field_t field, size_t size_of_written_sector_data) { float target = 0; bool history_included = false; /* Set the key of the requested field in the check-in JSON string */ if(field == HISTORY_TEMP_FIELD) n += snprintf(buff + n, len - n, ",\"tempC\":["); else if(field == HISTORY_HUMI_FIELD) n += snprintf(buff + n, len - n, ",\"humidity\":["); else if(field == HISTORY_THERM_FIELD) n += snprintf(buff + n, len - n, ",\"TcTemp\":["); /* make sure that the size of written data in the nvs-sector is more than 0 (make sure that there are some data) */ if(size_of_written_sector_data) { /* Include all the values for the requested field in the check-in JSON string */ for (uint8_t x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(_logs[x].logHistoryRecorded) { /* Get the value of the field "field" and index "x" and store it in the variable "target" */ target = data_get_history_field_float_values(x,field); /* Check if the index is the first index */ if(x == 0) n += snprintf(buff + n, len - n, "%0.2f",target); else n += snprintf(buff + n, len - n, ",%0.2f",target); /**/ history_included = true; } } } /* get the current data of that field */ if(field == HISTORY_TEMP_FIELD) target = get_temperature_data(); else if(field == HISTORY_HUMI_FIELD) target = get_humidity_data(); else if(field == HISTORY_THERM_FIELD) target = get_thermocouple_data(); /* Check if need to append the current sensor reading */ if((number_of_check_in_to_do - checkin_cycle_counter) == 1) { /* Check whether we are posting the current readings only or history¤t readings ? */ if(history_included) { n += snprintf(buff + n, len - n, ",%0.2f]", target); } else { n += snprintf(buff + n, len - n, "%0.2f]", target); } } else { n += snprintf(buff + n, len - n, "]"); } vTaskDelay(1/portTICK_PERIOD_MS); return n; } static size_t data_add_uint_history_to_buf(char* buff, uint32_t len, size_t n, historyLog_field_t field, size_t size_of_written_sector_data) { uint32_t target = 0; bool history_included = false; /* Set the key of the requested field in the check-in JSON string */ if(field == HISTORY_LIGHT_FIELD) n += snprintf(buff + n, len - n, ",\"LT_STATE\":["); else if(field == HISTORY_TRIG1_FIELD) n += snprintf(buff + n, len - n, ",\"TRIG1\":["); else if(field == HISTORY_TRIG2_FIELD) n += snprintf(buff + n, len - n, ",\"TRIG2\":["); else if(field == HISTORY_STAUS_FIELD) n += snprintf(buff + n, len - n, ",\"PWR_STATE\":["); else if(field == HISTORY_TIME_FIELD) n += snprintf(buff + n, len - n, ",\"server_time\":["); else if(field == HISTORY_XAXIS_FIELD) n += snprintf(buff + n, len - n, ",\"ACC_X_STATE\":["); else if(field == HISTORY_YAXIS_FIELD) n += snprintf(buff + n, len - n, ",\"ACC_Y_STATE\":["); else if(field == HISTORY_ZAXIS_FIELD) n += snprintf(buff + n, len - n, ",\"ACC_Z_STATE\":["); /* make sure that the size of written data in the nvs-sector is more than 0 (make sure that there are some data) */ if(size_of_written_sector_data) { /* Include all the values for the requested field in the check-in JSON string */ for (uint8_t x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(_logs[x].logHistoryRecorded) { /* Get the value of the field "field" and index "x" and store it in the variable "target" */ target = data_get_history_field_uint_values(x,field); /* Check if the index is the first index */ if(x == 0) n += snprintf(buff + n, len - n, "%ld",target); else n += snprintf(buff + n, len - n, ",%ld",target); /**/ history_included = true; } } } /* get the current data of that field */ if(field == HISTORY_LIGHT_FIELD) target = ((get_light_data() > esp_settings->lightSensorLevel)?1:0); else if(field == HISTORY_TRIG1_FIELD) target = g_triggerFlags1 ; else if(field == HISTORY_TRIG2_FIELD) target = g_triggerFlags2 ; else if(field == HISTORY_STAUS_FIELD) target = (1 & (!g_usbConnected)); else if(field == HISTORY_XAXIS_FIELD) target = get_accel_x(); else if(field == HISTORY_YAXIS_FIELD) target = get_accel_y(); else if(field == HISTORY_ZAXIS_FIELD) target = get_accel_z(); else if(field == HISTORY_TIME_FIELD) { target = g_wakeUpTime; } /* Check if need to append the current sensor reading */ if((number_of_check_in_to_do - checkin_cycle_counter) == 1) { /* Check whether we are posting the current readings only or history¤t readings ? */ if(history_included) { n += snprintf(buff + n, len - n, ",%ld]", target); } else { n += snprintf(buff + n, len - n, "%ld]", target); } } else { n += snprintf(buff + n, len - n, "]"); } vTaskDelay(1/portTICK_PERIOD_MS); return n; } #if 0 static size_t data_add_rssi_history_to_buf(char* buff, uint32_t len, size_t n, size_t size_of_written_sector_data) { int32_t target = 0; bool history_included = false; /* Set the key of the requested field in the check-in JSON string */ n += snprintf(buff + n, len - n, ",\"RSSI\":["); /* make sure that the size of written data in the nvs-sector is more than 0 (make sure that there are some data) */ if(size_of_written_sector_data) { /* Include all the values for the requested field in the check-in JSON string */ for (uint8_t x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(_logs[x].logHistoryRecorded) { /* Get the value of the field "field" and index "x" and store it in the variable "target" */ target = _logs[x].logRSSI; /* Check if the index is the first index */ if(x == 0) n += snprintf(buff + n, len - n, "%ld",target); else n += snprintf(buff + n, len - n, ",%ld",target); /**/ history_included = true; } } } /* get the current data of that field */ target = ((wifi_station_connected())? data_get_wifi_rssi() : modem_Rssi()); /* Check if need to append the current sensor reading */ if((number_of_check_in_to_do - checkin_cycle_counter) == 1) { /* Check whether we are posting the current readings only or history¤t readings ? */ if(history_included) { n += snprintf(buff + n, len - n, ",%ld]", target); } else { n += snprintf(buff + n, len - n, "%ld]", target); } } else { n += snprintf(buff + n, len - n, "]"); } vTaskDelay(1/portTICK_PERIOD_MS); return n; } static size_t data_add_time_history_to_buf(char* buff, uint32_t len, size_t n, size_t size_of_written_sector_data) { time_t target = 0; bool history_included = false; /* Set the key of the requested field in the check-in JSON string */ n += snprintf(buff + n, len - n, ",\"server_time\":["); /* make sure that the size of written data in the nvs-sector is more than 0 (make sure that there are some data) */ if(size_of_written_sector_data) { /* Include all the values for the requested field in the check-in JSON string */ for (uint8_t x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(_logs[x].logHistoryRecorded) { /* Get the value of the field "field" and index "x" and store it in the variable "target" */ target = _logs[x].logCheckInTime; /* Check if the index is the first index */ if(x == 0) n += snprintf(buff + n, len - n, "%llu",target); else n += snprintf(buff + n, len - n, ",%llu",target); /**/ history_included = true; } } } /* get the current data of that field */ time(&g_wakeUpTime); /* Check if need to append the current sensor reading */ if((number_of_check_in_to_do - checkin_cycle_counter) == 1) { /* Check whether we are posting the current readings only or history¤t readings ? */ if(history_included) { n += snprintf(buff + n, len - n, ",%llu]", g_wakeUpTime); } else { n += snprintf(buff + n, len - n, "%llu]", g_wakeUpTime); } } else { n += snprintf(buff + n, len - n, "]"); } vTaskDelay(1/portTICK_PERIOD_MS); return n; } #endif /**old message format * {"id":2765778,"mac_addr":"D2:33:2A:BF:71:3C","attempt":1, * "tempC":[22.52],"humidity":[37.50],"server_time":[1674766545], * "wifi_connect_time":[1],"RSSI":[-57],"LT_STATE":[0],"PWR_STATE":[0], * "TRIG1":[0],"TRIG2":[0],"vcc":3.40,"version":2001,"tmpThA_GP":71.11, * "tmpThA_GN":70.00,"tmpThB_GP":71.11,"tmpThB_GN":70.00,"tmpThC_GP":71.11, * "tmpThC_GN":70.00,"tmpThD_GP":-44.44,"tmpThD_GN":-45.56,"tmpThE_GP":-44.44, * "tmpThE_GN":-45.56,"tmpThF_GP":-44.44,"tmpThF_GN":-45.56,"humThA_GP":103.00, * "humThA_GN":101.00,"humThB_GP":103.00,"humThB_GN":101.00,"humThC_GP":103.00, * "humThC_GN":101.00,"humThD_GP":-1.00,"humThD_GN":-3.00,"humThE_GP":-1.00, * "humThE_GN":-3.00,"humThF_GP":-1.00,"humThF_GN":-3.00,"tcThA_GP":71.11, * "tcThA_GN":70.00,"tcThB_GP":71.11,"tcThB_GN":70.00,"tcThC_GP":71.11, * "tcThC_GN":70.00,"tcThD_GP":-168.33,"tcThD_GN":-169.44,"tcThE_GP":-168.33, * "tcThE_GN":-169.44,"tcThF_GP":-168.33,"tcThF_GN":-169.44,"sendSecs":900, * "postURLMax":3,"urlconnect":"testdevice.tempstickapi.com"} * * */ /*new message format*/ /*{"id":"TS00123456","mac_addr":"BC:3C:86:A3:C9:C8","attempt":1,"tempC":[17.94], * "humidity":[33.70],"server_time":[2],"wifi_connect_time":[4],"RSSI":[-65], * "TRIG1":[0],"TRIG2":[128],"w":1,"vcc":3.21,"version":2004,"cVersion":2002, * "maxTemp":201.00,"minTemp":-100.00,"maxHum":101.00,"minHum":-1.00,"maxTcTemp":201.00, * "minTcTemp":-100.00,"maxProbeTemp":201.00,"minProbeTemp":-100.00,"lightTh":129, * "acclTh":80,"alertSecs":300,"sendSecs":300,"postURLMax":0,"urlconnect":"v2.idealsciences2.com"}*/ void data_create_checkin_string(char *buff, size_t len) { uint32_t chipId = 0; char chipIdHex[8]; uint8_t mac_base[6] = {0}; char mac_str[20]; size_t n = 0; size_t size_of_written_sector_data = 0; uint8_t sector_to_read_from = nvm_get_last_posted_history_sector() + 1; /**/ data_show_history(sector_to_read_from, false, &size_of_written_sector_data); esp_efuse_mac_get_default(mac_base); esp_read_mac(mac_base, ESP_MAC_WIFI_STA); sprintf(chipIdHex, "%02X%02X%02X", mac_base[5], mac_base[4], mac_base[3]); chipId = (uint32_t)strtol(chipIdHex, NULL, 16); sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); strcpy(buff, ""); //ID n = snprintf(buff, len, "{\"id\":%ld", chipId); // {"id":2765778, //MAC ID n += snprintf(buff + n, len - n, ",\"mac_addr\":\"%s\"", mac_str); //"mac_addr":"D2:33:2A:BF:71:3C" //IMEI n += snprintf(buff + n, len - n, ",\"IMEI\":\"%s\"", modem_get_imei()); //"IMEI":"866349048889004" //ICCID n += snprintf(buff + n, len - n, ",\"SIM number\":\"%s\"", modem_get_iccid()); //"SIM number":"8901240205100030994" //Attempt n += snprintf(buff + n, len - n, ",\"attempt\":%d", checkInAttemptNumber);//,"attempt":1 //Temperature Sensor if(isTempPresent) { //n += snprintf(buff + n, len - n, ",\"tempC\":[%f]", get_temperature_data()); // ,"tempC":[22.52] n = data_add_float_history_to_buf(buff,len,n,HISTORY_TEMP_FIELD,size_of_written_sector_data); //1 //n += snprintf(buff + n, len - n, ",\"humidity\":[%f]", get_humidity_data()); // ,"humidity":[37.50] n = data_add_float_history_to_buf(buff,len,n,HISTORY_HUMI_FIELD,size_of_written_sector_data); //2 } #if 1 //Thermocouple Sensor if(isThermocouplePresent) { //n += snprintf(buff + n, len - n, ",\"TcTemp\":[%f]", get_thermocouple_data()); n = data_add_float_history_to_buf(buff,len,n,HISTORY_THERM_FIELD,size_of_written_sector_data); //3 } //Accelerometer Sensor if(isAccelPresent) { /*n += snprintf(buff + n, len - n, ",\"ACC_X_STATE\":[%d]", get_accel_x()); n += snprintf(buff + n, len - n, ",\"ACC_Y_STATE\":[%d]", get_accel_y()); n += snprintf(buff + n, len - n, ",\"ACC_Z_STATE\":[%d]", get_accel_z());*/ n = data_add_uint_history_to_buf(buff,len,n,HISTORY_XAXIS_FIELD,size_of_written_sector_data); //4 n = data_add_uint_history_to_buf(buff,len,n,HISTORY_YAXIS_FIELD,size_of_written_sector_data); //5 n = data_add_uint_history_to_buf(buff,len,n,HISTORY_ZAXIS_FIELD,size_of_written_sector_data); //6 } //Light Sensor State //n += snprintf(buff + n, len - n, ",\"LT_STATE\":[%d]", (light_mv > 800)?1:0);// ,"LT_STATE":[0] n = data_add_uint_history_to_buf(buff,len,n,HISTORY_LIGHT_FIELD,size_of_written_sector_data); //7 //Power State //n += snprintf(buff + n, len - n, ",\"PWR_STATE\":[%d]", 1 & (!g_usbConnected));// ,"PWR_STATE":[0] n = data_add_uint_history_to_buf(buff,len,n,HISTORY_STAUS_FIELD,size_of_written_sector_data); //8 #endif //Server time //time_t timeNow; //time(&g_wakeUpTime); //n += snprintf(buff + n, len - n, ",\"server_time\":[%llu]", g_wakeUpTime);// ,"server_time":[1674766545] //n = data_add_time_history_to_buf(buff,len,n,size_of_written_sector_data); //9 n = data_add_uint_history_to_buf(buff,len,n,HISTORY_TIME_FIELD,size_of_written_sector_data); //9 // Comms medium if(comms_medium == COMMS_MEDIUM_CELL) n += snprintf(buff + n, len - n, ",\"comms_medium\":\"LTE\""); else { // wifi connect time n += snprintf(buff + n, len - n, ",\"wifi_connect_time\":[%ld]",g_wifiConnectTime);// ,"wifi_connect_time":[1] // Comms medium n += snprintf(buff + n, len - n, ",\"comms_medium\":\"WIFI\""); } // Comms mode n += snprintf(buff + n, len - n, ",\"comms_mode\":[%d]",comms_mode); //RSSI n += snprintf(buff + n, len - n, ",\"RSSI\":[%ld]", ((wifi_station_connected())? data_get_wifi_rssi() : modem_Rssi())); //n = data_add_rssi_history_to_buf(buff,len,n,size_of_written_sector_data); //10 // trigger 1 value //n += snprintf(buff + n, len - n, ",\"TRIG1\":[%ld]", g_triggerFlags1);// ,"TRIG1":[0] n = data_add_uint_history_to_buf(buff,len,n,HISTORY_TRIG1_FIELD,size_of_written_sector_data); //11 // trigger 2 value //n += snprintf(buff + n, len - n, ",\"TRIG2\":[%ld]", g_triggerFlags2);// ,"TRIG1":[0] n = data_add_uint_history_to_buf(buff,len,n,HISTORY_TRIG2_FIELD,size_of_written_sector_data); //12 //w //n += snprintf(buff + n, len - n, ",\"TcTemp\":[%f]", get_thermocouple_data()); //Battery Voltage n += snprintf(buff + n, len - n, ",\"vcc\":%0.2f", g_voltage);// ,"vcc":3.40 //Firmware Version n += snprintf(buff + n, len - n, ",\"version\":%ld", g_version); // ,"version":2004 // n += snprintf(buff + n, len - n, ",\"cVersion\":%ld", ); // ,"cVersion":2002 //TempHumi_mode & maxTemp & minTemp n += snprintf(buff + n, len - n, ",\"tempC_mode\":1"); n += snprintf(buff + n, len - n, ",\"maxTemp\":%0.2f", esp_settings->maxTemp); // ,"maxTemp":201 n += snprintf(buff + n, len - n, ",\"minTemp\":%0.2f", esp_settings->minTemp ); //,"minTemp":-100 //maxHum & minHum & humidity_mode n += snprintf(buff + n, len - n, ",\"humidity_mode\":1"); n += snprintf(buff + n, len - n, ",\"maxHum\":%ld", esp_settings->maxHum); // ,"maxHum":101 n += snprintf(buff + n, len - n, ",\"minHum\":%ld", esp_settings->minHum ); //,"minHum":-1 //maxTcTemp & minTcTemp & TcTemp_mode n += snprintf(buff + n, len - n, ",\"TcTemp_mode\":%d",esp_settings->thermocoupleMode); n += snprintf(buff + n, len - n, ",\"maxTcTemp\":%0.2f", esp_settings->maxTcTemp); // ,"maxTcTemp":201 n += snprintf(buff + n, len - n, ",\"minTcTemp\":%0.2f", esp_settings->minTcTemp ); //,"minTcTemp":-100 //maxProbeTemp & minProbeTemp n += snprintf(buff + n, len - n, ",\"maxProbeTemp\":%0.2f", esp_settings->maxProbeTemp); // ,"maxProbeTemp":201 n += snprintf(buff + n, len - n, ",\"minProbeTemp\":%0.2f", esp_settings->minProbeTemp ); //,"minProbeTemp":-100 //acclTh & accl_mode n += snprintf(buff + n, len - n, ",\"accl_mode\":%d",esp_settings->accelerometerMode); n += snprintf(buff + n, len - n, ",\"acclTh\":%d", esp_settings->accelerometerLevel ); //,"acclTh":-100 //lightTh & light_mode n += snprintf(buff + n, len - n, ",\"light_mode\":%d",esp_settings->lightSensorMode); n += snprintf(buff + n, len - n, ",\"lightTh\":%d", esp_settings->lightSensorLevel ); //,"lightTh":-100 //powerMonitor_mode n += snprintf(buff + n, len - n, ",\"powerMonitor_mode\":%d",esp_settings->powerMonitorMode); //alert Interval n += snprintf(buff + n, len - n, ",\"alertSecs\":%ld", esp_settings->alertInterval); // ,"alertInterval":300 //send Interval n += snprintf(buff + n, len - n, ",\"sendSecs\":%ld", esp_settings->sendInterval); // ,"sendSecs":900 //POST URL Max n += snprintf(buff + n, len - n, ",\"postURLMax\":%ld",esp_settings->postURLMax); // ,"postURLMax":3 //POST URL Max data_set_urlConnect(); #if (TEMPSTICK_SERVER == 1) n += snprintf(buff + n, len - n, ",\"urlconnect\":\"%s\"",(char*)(&urlConnect[8])); //,"urlconnect":"testdevice.tempstickapi.com" #else n += snprintf(buff + n, len - n, ",\"urlconnect\":\"%s\"",(char*)(&urlConnect[7])); //,"urlconnect":"testdevice.tempstickapi.com" #endif //Closure strcat(buff, "}"); } void data_update_trigger_flags(void) { /*Reset the trigger variables before setting the new flags*/ g_triggerFlags1 = 0; g_triggerFlags2 = 0; /* Setting the bits of TRIGGER_1 variable */ if(ulp_ulp_strobedTemperatureFlags & STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD) g_triggerFlags1 |= STROBED_TEMPERATURE_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; if(ulp_ulp_strobedTemperatureFlags & STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD) g_triggerFlags1 |= STROBED_TEMPERATURE_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; if(ulp_ulp_strobedHumidityFlags & STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD) g_triggerFlags1 |= STROBED_HUMIDITY_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; if(ulp_ulp_strobedHumidityFlags & STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD) g_triggerFlags1 |= STROBED_HUMIDITY_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; if(ulp_ulp_strobedThermocoupleFlags & STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD) g_triggerFlags1 |= STROBED_THERMOCOUPLE_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; if(ulp_ulp_strobedThermocoupleFlags & STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD) g_triggerFlags1 |= STROBED_THERMOCOUPLE_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; /*if(ulp_ulp_strobedDigitalTempProbes & STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD) g_triggerFlags1 |= STROBED_EXTERNAL_TEMP_PROBE_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; if(ulp_ulp_strobedDigitalTempProbes & STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD) g_triggerFlags1 |= STROBED_EXTERNAL_TEMP_PROBE_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; */ if(ulp_ulp_strobedMiscFlags & STROBED_MISC_DEVICE_OPERATE_IN_ALERT_MODE) g_triggerFlags1 |= STROBED_DEVICE_OPERATE_IN_ALERT_MODE; /* Setting the bits of TRIGGER_2 variable */ if(ulp_ulp_strobedMiscFlags & STROBED_MISC_REGULAR_SCHEDULED_CHECK_IN) g_triggerFlags2 |= STROBED_REGULAR_SCHEDULED_SENDINTERVAL_CHECKIN; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHANGE_FROM_BATTERY_TO_USB) g_triggerFlags2 |= STROBED_POWER_CHANGE_FROM_BATTERY_TO_USB; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHANGE_FROM_USB_TO_BATTERY) g_triggerFlags2 |= STROBED_POWER_CHANGE_FROM_USB_TO_BATTERY; if(ulp_ulp_strobedMotionFlags & STROBED_MOTION_MOVEMENT_DETECTED) g_triggerFlags2 |= STROBED_MOTION_MOVEMENT_WAS_DETECTED; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHANGE_FROM_LIGHT_TO_DARK) g_triggerFlags2 |= STROBED_LIGHT_TRANSITION_FROM_LIGHT_TO_DARK; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHANGE_FROM_DARK_TO_LIGHT) g_triggerFlags2 |= STROBED_LIGHT_TRANSITION_FROM_DARK_TO_LIGHT; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHECK_IN_REQ_AFTER_POWER_ON) g_triggerFlags2 |= STROBED_CHECK_IN_REQUESTED_AFTER_POWER_ON; if(ulp_ulp_strobedMiscFlags & STROBED_MISC_CHECK_IN_REQUESTED) g_triggerFlags2 |= STROBED_BUTTON_CHECK_IN_REQUESTED; // Pushbutton. data_clear_sensor_strobes(0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF); //Clear all strobed_flags for the next cycle ESP_LOGI(TAG,"g_tiggerFlags1 and g_tiggerFlags1 have been updated successfully"); ESP_LOGI(TAG,"g_triggerFlags1 = 0x%X (hex)",(unsigned int)g_triggerFlags1); ESP_LOGI(TAG,"g_triggerFlags2 = 0x%X (hex)",(unsigned int)g_triggerFlags2); } void data_parse_http_response(const char *http_resp) { /*1- parse limits from the response*/ data_parse_limits(http_resp); /*2- parse intervals from the response*/ data_parse_intervals(http_resp); /*3- parse intervals from the response*/ data_parse_dynamicVariables(http_resp); /*4- parse temperature from the response*/ data_parse_temperature(http_resp); /*5- parse humidity from the response*/ data_parse_humidity(http_resp); /*6- parse thermocouple from the response*/ data_parse_thermocouple(http_resp); /*7- parse lightSensor from the response*/ data_parse_lightSensor(http_resp); /*8- parse accelerometer from the response*/ data_parse_accelerometer(http_resp); /*9- parse power from the response*/ data_parse_power(http_resp); /*10- parse pushbuttons from the response*/ data_parse_pushbutton(http_resp); } void data_processSensorModes(sensorType_t sensor) { uint16_t tempFlags16; tempFlags16 = 0; switch(sensor) { case TEMPERATURE_SENSOR: break; case HUMIDITY_SENSOR: break; case THERMOCOUPLE_SENSOR: if(isThermocouplePresent) { switch(esp_settings->thermocoupleMode) { case 0: ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_WHEN_THERMOCOUPLE_CROSSES_LIMITS; // Disable thermocouple interrupt triggers //tempFlags16 |= ( STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_A | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_A | STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_B | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_B | STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_C | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_C | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_D | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_D | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_E | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_E | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_F | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_F ); tempFlags16 |= ( STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD); break; case 1: ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_WHEN_THERMOCOUPLE_CROSSES_LIMITS; // Enable thermocouple interrupt triggers break; default: ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_WHEN_THERMOCOUPLE_CROSSES_LIMITS; // Disable thermocouple interrupt triggers //tempFlags16 |= ( STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_A | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_A | STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_B | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_B | STROBED_SENSOR_MEASUREMENT_EXCEEDED_THRESHOLD_C | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_ABOVE_THRESHOLD_C | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_D | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_D | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_E | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_E | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_THRESHOLD_F | STROBED_SENSOR_MEASUREMENT_RETURNED_FROM_BELOW_THRESHOLD_F ); tempFlags16 |= ( STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD | STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD); break; } data_clear_sensor_strobes(0,0,tempFlags16,0,0); } break; case LIGHT_SENSOR: /* 1- Check the first bit of lightSensorMode */ if(esp_settings->lightSensorMode & 0x01) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_LIGHT_TO_DARK; // Enable light-to-dark tempFlags16 |= STROBED_MISC_CHANGE_FROM_LIGHT_TO_DARK; } else { ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_LIGHT_TO_DARK; // Disable light-to-dark tempFlags16 |= STROBED_MISC_CHANGE_FROM_LIGHT_TO_DARK; } /* 2- Check the second bit of lightSensorMode */ if(esp_settings->lightSensorMode & 0x02) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_DARK_TO_LIGHT; // Enable dark-to-light tempFlags16 |= STROBED_MISC_CHANGE_FROM_DARK_TO_LIGHT; } else { ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_DARK_TO_LIGHT; // Disable dark-to-light tempFlags16 |= STROBED_MISC_CHANGE_FROM_DARK_TO_LIGHT; } /* This if block should be removed because if any of the first two bits were 1 then both condition will be set */ if(esp_settings->lightSensorMode & 0x03) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_LIGHT_TO_DARK; // Enable light-to-dark ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_DARK_TO_LIGHT; // Enable dark-to-light tempFlags16 |= STROBED_MISC_CHANGE_FROM_LIGHT_TO_DARK; tempFlags16 |= STROBED_MISC_CHANGE_FROM_DARK_TO_LIGHT; } data_clear_sensor_strobes(0,0,0,0,tempFlags16); break; case ACCELEROMETER_SENSOR: if(isAccelPresent) { setAccelerometerPowerState(); // Change state before clearing the interrupt flags. switch(esp_settings->accelerometerMode) { case 0: // Accelerometer triggers disabled. ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_MOVEMENT_DETECTION; tempFlags16 |= STROBED_MOTION_MOVEMENT_DETECTED; break; case 1: // "Bumping" motion triggers a check-in. ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_MOVEMENT_DETECTION; break; default: // Accelerometer triggers disabled. ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_MOVEMENT_DETECTION; tempFlags16 |= STROBED_MOTION_MOVEMENT_DETECTED; break; } i2c_clear_mc3419_int_flag(); data_clear_sensor_strobes(0,0,0,tempFlags16,0); } break; case POWER_MONITOR_SENSOR: /* 1- Check the first bit of powerMonitorMode */ if(esp_settings->powerMonitorMode & 0x01) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_SWITCH_FROM_BATTERY_TO_USB; // Enable battery-to-usb triggering tempFlags16 |= STROBED_MISC_CHANGE_FROM_BATTERY_TO_USB; } else { ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_SWITCH_FROM_BATTERY_TO_USB; // Disable battery-to-usb triggering tempFlags16 |= STROBED_MISC_CHANGE_FROM_BATTERY_TO_USB; } /* 2- Check the second bit of powerMonitorMode */ if(esp_settings->powerMonitorMode & 0x02) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY; // Enable usb-to-battery triggering tempFlags16 |= STROBED_MISC_CHANGE_FROM_USB_TO_BATTERY; } else { ulp_ulp_triggersThatCanWakeTheHost &= ~WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY; // Disable usb-to-battery triggering tempFlags16 |= STROBED_MISC_CHANGE_FROM_USB_TO_BATTERY; } /* This if block should be removed because if any of the first two bits were 1 then both condition will be set */ if(esp_settings->powerMonitorMode & 0x03) { ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_SWITCH_FROM_BATTERY_TO_USB; ulp_ulp_triggersThatCanWakeTheHost |= WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY; tempFlags16 |= STROBED_MISC_CHANGE_FROM_BATTERY_TO_USB; tempFlags16 |= STROBED_MISC_CHANGE_FROM_USB_TO_BATTERY; } data_clear_sensor_strobes(0,0,0,0,tempFlags16); break; } } uint8_t data_process_tempHumi_thresholds(float raw_data, float prev_raw_data, sensorType_t sensor) { //uint8_t enable_thsProcess = 1; uint8_t useTokens = 0; uint8_t wakeHostForStrobedTrigger = 0; //uint8_t *tokenregister = NULL; switch(sensor) { case LIGHT_SENSOR: break; case ACCELEROMETER_SENSOR: break; case POWER_MONITOR_SENSOR: break; case TEMPERATURE_SENSOR: /* Set the tokens register to be ThermoCouple token-registers */ //tokenregister = &(esp_settings->temperatureTokens); /* Process thresholds for ENS210-TempData*/ if((raw_data > esp_settings->maxTemp) && (prev_raw_data < esp_settings->maxTemp)) { (ulp_ulp_strobedTemperatureFlags) |= STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; useTokens = 1; } else if((raw_data < esp_settings->minTemp) && (prev_raw_data > esp_settings->minTemp)) { (ulp_ulp_strobedTemperatureFlags) |= STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; useTokens = 1; } break; case HUMIDITY_SENSOR: /* Set the tokens register to be Humidity token registers */ //tokenregister = &(esp_settings->humidityTokens); /* Process thresholds for ENS210-HumiData*/ if((raw_data > esp_settings->maxHum) && (prev_raw_data < esp_settings->maxHum)) { (ulp_ulp_strobedHumidityFlags) |= STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; useTokens = 1; } else if((raw_data < esp_settings->minHum) && (prev_raw_data > esp_settings->minHum)) { (ulp_ulp_strobedHumidityFlags) |= STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; useTokens = 1; } break; case THERMOCOUPLE_SENSOR: if((ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_WHEN_THERMOCOUPLE_CROSSES_LIMITS)) { /* Set the tokens register to be ThermoCouple token-registers */ //tokenregister = &(esp_settings->thermocoupleTokens); /* Process thresholds for MCP9600-TcData*/ if((raw_data > esp_settings->maxTcTemp) && (prev_raw_data < esp_settings->maxTcTemp)) { (ulp_ulp_strobedThermocoupleFlags) |= STROBED_SENSOR_MEASUREMENT_EXCEEDED_UPPER_THRESHOLD; useTokens = 1; } else if((raw_data < esp_settings->minTcTemp) && (prev_raw_data > esp_settings->minTcTemp)) { (ulp_ulp_strobedThermocoupleFlags) |= STROBED_SENSOR_MEASUREMENT_FELL_BELOW_LOWER_THRESHOLD; useTokens = 1; } break; } break; } /* Process the sensor-Tokens*/ if((useTokens == 1)) { wakeHostForStrobedTrigger = 1; ESP_LOGI(TAG,"Sensor flags have been set to wake the host"); } return wakeHostForStrobedTrigger; } uint8_t data_process_lightSen_thresholds(uint32_t prev_raw_data, uint32_t raw_data) { uint8_t wakeHostForStrobedTrigger = 0; /* Check if light now has been detected and in the previous state there were no light*/ if((raw_data > esp_settings->lightSensorLevel) && (prev_raw_data < esp_settings->lightSensorLevel)) { //ESP_LOGI(TAG, "Light Detected --> Set DARK_TO_LIGHT flag "); /* Check if we should do check-in when changing from dark to light*/ if(ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_ON_DARK_TO_LIGHT) { ulp_ulp_strobedMiscFlags |= STROBED_MISC_CHANGE_FROM_DARK_TO_LIGHT; wakeHostForStrobedTrigger = 1; /* Reduce light tokens by 1*/ /*if(esp_settings->lightSensorTokens) { esp_settings->lightSensorTokens--; wakeHostForStrobedTrigger = 1; }*/ } } else if((raw_data < esp_settings->lightSensorLevel) && (prev_raw_data > esp_settings->lightSensorLevel)) { //ESP_LOGI(TAG, "Light didn't detected --> Set LIGHT_TO_DARK flag "); /* Check if we should do check-in when changing from light to dark*/ if(ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_ON_LIGHT_TO_DARK) { ulp_ulp_strobedMiscFlags |= STROBED_MISC_CHANGE_FROM_LIGHT_TO_DARK; wakeHostForStrobedTrigger = 1; /* Reduce light tokens by 1*/ /*if(esp_settings->lightSensorTokens) { esp_settings->lightSensorTokens--; wakeHostForStrobedTrigger = 1; }*/ } } else { /*If none of the previous conditions are true then ---> current light_data is within Light_thresholds*/ //ESP_LOGI(TAG," Light_GP > current_data > Light_GN "); } return wakeHostForStrobedTrigger; } void data_process_power_thresholds(void) { /* Check if switch occurred from battery to usb*/ if((g_usbConnected == 1) && (g_prevUsbConnected == 0)) { /* Set the switch-to-usb strobe*/ if(ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_ON_SWITCH_FROM_BATTERY_TO_USB) { ulp_ulp_strobedMiscFlags |= STROBED_MISC_CHANGE_FROM_BATTERY_TO_USB; // Rise a trigger flag to do the check-in process before going to deep-sleep wakeHostForStrobedTrigger2++; /* Reduce the power tokens by 1*/ /*if(esp_settings->powerMonitorTokens) esp_settings->powerMonitorTokens--;*/ } } else if((g_usbConnected == 0) && (g_prevUsbConnected == 1)) { /* Set the switch-to-battery strobe*/ if(ulp_ulp_triggersThatCanWakeTheHost & WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY) { ulp_ulp_strobedMiscFlags |= STROBED_MISC_CHANGE_FROM_USB_TO_BATTERY; // Rise a trigger flag to do the check-in process before going to deep-sleep wakeHostForStrobedTrigger2++; /* Reduce the power tokens by 1*/ /*if(esp_settings->powerMonitorTokens) esp_settings->powerMonitorTokens--;*/ } else { ESP_LOGI(TAG,"g_triggersThatCanWakeTheHost & WAKE_HOST_ON_SWITCH_FROM_USB_TO_BATTERY = failed"); } } } void data_save_history(void) { ESP_LOGI(TAG, "data_save_history()"); /* Check if the current history array is full */ if (esp_settings->historyIndex > (NVM_MAX_NUMBER_OF_IN_ONE_SECTOR - 1)) { /* If so then clear it (clear the current history array) and start storing again from index 0 * in NVM it will also starts storing in a new history_sector */ data_clear_history(); esp_settings->historyIndex = 0; } _logs[esp_settings->historyIndex].logTemp = get_temperature_data(); _logs[esp_settings->historyIndex].logHumidity = get_humidity_data(); _logs[esp_settings->historyIndex].logThermocoupleTemp = get_thermocouple_data(); _logs[esp_settings->historyIndex].logLight = ((get_light_data() > esp_settings->lightSensorLevel)?1:0); _logs[esp_settings->historyIndex].logXaxis = get_accel_x(); _logs[esp_settings->historyIndex].logYaxis = get_accel_y(); _logs[esp_settings->historyIndex].logZaxis = get_accel_z(); _logs[esp_settings->historyIndex].logCheckInTime = g_wakeUpTime; //_logs[esp_settings->historyIndex].logRSSI = ((wifi_station_connected())? data_get_wifi_rssi() : modem_Rssi()); _logs[esp_settings->historyIndex].logStatusFlags = (1 & (!g_usbConnected)); _logs[esp_settings->historyIndex].logTriggerFlags1 = g_triggerFlags1; _logs[esp_settings->historyIndex].logTriggerFlags2 = g_triggerFlags2; _logs[esp_settings->historyIndex].logHistoryRecorded = true; esp_settings->historyIndex++; if (esp_settings->historyIndex > (NVM_MAX_NUMBER_OF_IN_ONE_SECTOR - 1)) { esp_settings->historyIndex = 0; } /* Store history data in NVM */ nvm_write_history_data(_logs); } void data_show_history(uint8_t sector, bool print_logs, size_t* size_of_written_sector_data) { ESP_LOGI(TAG, "data_show_history()"); /* Read the NVS-sector from the NVM storage */ *size_of_written_sector_data = nvm_read_history_data(_logs,sector); /* if print_logs flag is true then print the LOGS of the history data */ if(print_logs) { for (uint8_t x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(_logs[x].logHistoryRecorded) { printf("I: %d", x); if(isTempPresent) { printf(" Temp: %f", _logs[x].logTemp); printf(" Hum: %f", _logs[x].logHumidity); } if(isAccelPresent) { printf(" X axis: %d", _logs[x].logXaxis); printf(" Y axis: %d", _logs[x].logYaxis); printf(" Z axis: %d", _logs[x].logZaxis); } if(isThermocouplePresent) { printf(" TcTemp: %f", _logs[x].logThermocoupleTemp); } printf(" Time: %ld", _logs[x].logCheckInTime); //printf(" RSSI: %d", _logs[x].logRSSI); printf(" Status: 0x%X", _logs[x].logStatusFlags); printf(" Triggers, Part 1: 0x%X", (unsigned int)_logs[x].logTriggerFlags1); printf(" Triggers, Part 2: 0x%X\r\n", (unsigned int)_logs[x].logTriggerFlags2); } } } } bool data_clear_history(void) { bool dataChanged; uint8_t x; dataChanged = false; ESP_LOGI(TAG, "data_clear_history()"); for (x = 0; x < NVM_MAX_NUMBER_OF_IN_ONE_SECTOR; x++) { if(false != _logs[x].logHistoryRecorded) { dataChanged = true; _logs[x].logHistoryRecorded = false; } } if(0 != esp_settings->historyIndex) { dataChanged = true; esp_settings->historyIndex = 0; /* Clear all the sectors from the NVM storage*/ //nvm_clear_history_sector(NVM_HISTORY_ALL_SECTORS); } return dataChanged; } /* rtcRamStruc functions */ void data_initialize_rtc_ram(void) { _rtcRamData.timeOfLastRadioCalibration = 0; _rtcRamData.checkInClock = 0; _rtcRamData.retry1Clock = 0; _rtcRamData.retry2Clock = 0; _rtcRamData.lteRssi = -128; // INITIALIZE OPERATING MODE if(CHECK_IN_MODE != _rtcRamData.operatingMode) { _rtcRamData.operatingMode = CHECK_IN_MODE; //ON_BOARDING_MODE; //made it check-in by default for testing } _rtcRamData.initializationVectorCreated = false; _rtcRamData.checkInCount = 0; _rtcRamData.temperatureAtLastRadioCalibration = 200; // Out-of-range for normal operation, so a radio calibration will occur before the next radio use. _rtcRamData.retriesAreInProgress = false; } ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void data_set_ap_mac_addr(uint8_t *bssid) { for(int i=0; i<6; i++) { _rtcRamData.bssid[i] = bssid[i]; } } uint8_t* data_get_ap_mac_addr(void) { return ((uint8_t*)&_rtcRamData.bssid[0]); } void data_set_local_ip_addr(esp_netif_ip_info_t* ip_infos) { _rtcRamData.localIp.ip.addr = ip_infos->ip.addr; _rtcRamData.localIp.gw.addr = ip_infos->gw.addr; _rtcRamData.localIp.netmask.addr = ip_infos->netmask.addr; } uint32_t data_get_ip_addr(void) { return _rtcRamData.localIp.ip.addr; } uint32_t data_get_gw_addr(void) { return _rtcRamData.localIp.gw.addr; } uint32_t data_get_netmask_addr(void) { return _rtcRamData.localIp.netmask.addr; } void data_set_wifi_channel(uint8_t channel) { _rtcRamData.wifiChannel = channel; } uint8_t data_get_wifi_channel(void) { return _rtcRamData.wifiChannel; } void data_set_wifi_rssi(int32_t rsi) { _rtcRamData.wifi_rssi = rsi; } int32_t data_get_wifi_rssi(void) { return _rtcRamData.wifi_rssi; } void data_set_main_and_backup_dns(esp_netif_dns_info_t* dns1, esp_netif_dns_info_t* dns2) { _rtcRamData.dns1.ip.u_addr.ip4.addr = dns1->ip.u_addr.ip4.addr; _rtcRamData.dns2.ip.u_addr.ip4.addr = dns2->ip.u_addr.ip4.addr; } uint32_t data_get_mode(void) { return _rtcRamData.operatingMode; } void data_clearWifiConnectionSettings(void) { _rtcRamData.wifiChannel = 1; // FCC allows only channels 1 through 13 in the USA, but 12 and 13 must be low power, which I don't think we can control. My linksys router only allows channels 1-11. memset(_rtcRamData.bssid, 0, sizeof(_rtcRamData.bssid)); _rtcRamData.localIp.ip.addr = 0; _rtcRamData.localIp.gw.addr = 0; _rtcRamData.localIp.netmask.addr = 0; _rtcRamData.dns1.ip.u_addr.ip4.addr = 0; _rtcRamData.dns2.ip.u_addr.ip4.addr = 0; } <<<<<<< HEAD ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*******************************************************************/ /* Buffer(Json Sample) */ /*{ "request": "settings", "time":1675859084, "id":10608508, * "SensorInt":1, "ConfigUpdate":0, "McuUpdate:0", "ModemUpdate":0 } */ /*******************************************************************/ esp_err_t data_parsing_config(char *buff,int len){ esp_err_t retval = ESP_FAIL; <<<<<<< HEAD char *ret = NULL; ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) char server_request[11]={0}; // char setting_req[]="settings"; // ret = strstr(buff, (const char*)"settings"); // data_parse_String_value(server_request,"request",buff); // if( ret != NULL ){ <<<<<<< HEAD if(1){ ======= if(1){ >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) //retval = data_parse_uint_value(&g_server_time,"time", buff); retval = data_parse_uint_value(&g_ID,"id", buff); retval = data_parse_uint_value(&g_SensorInt,"SensorInt", buff); retval = data_parse_uint_value(&g_ConfigUpdate,"ConfigUpdate", buff); retval = data_parse_uint_value(&g_McuUpdate,"McuUpdate", buff); retval = data_parse_uint_value(&g_ModemUpdate,"ModemUpdate", buff); <<<<<<< HEAD ESP_LOGI(TAG, "ConfigUpdate: %ld McuUpdate: %ld ModemUpdate: %ld", g_ConfigUpdate, g_McuUpdate, g_ModemUpdate); if(g_McuUpdate == 1) wifi_ota_start_firmware_update(IMEI); } else { ESP_LOGI(TAG, "Invalid request :%s",server_request); } ======= ESP_LOGI(TAG, "ConfigUpdate: %luMcuUpdate: %lu ModemUpdate: %lu", g_ConfigUpdate, g_McuUpdate, g_ModemUpdate); g_McuUpdate = 1; //g_ConfigUpdate = 1; if(g_ConfigUpdate == 1) ESP_LOGI(TAG, "Configuration update = 1 "); } if(g_McuUpdate == 1){ ESP_LOGI(TAG, "g_McuUpdate update = 1 "); } else { ESP_LOGI(TAG, "Invalid request :%s",server_request); } >>>>>>> 4ea13f8 (Added azuma wifi switch backup code) return retval; } /****************************************************************************/ /* function input maxretrynum = HTTP_RETRY_COUNT = 5 httpRetryCnt is the current retry count */ esp_err_t check_in_attempts_count( int httpRetryCnt, int maxretrynum ) { esp_err_t retval = ESP_OK; checkInAttemptNumber = 1 + maxretrynum - httpRetryCnt; return retval; } <<<<<<< HEAD /* should use in main.c to initiate sendDetails var*/ void init_send_Details(void) { esp_settings->sendDetails = true; } /********************************************************/ int32_t data_get_postUrlMax(void){ return esp_settings->postURLMax; } void data_init_postUrlMax(int32_t val){ esp_settings->postURLMax = val; // ESP_LOGI(TAG,"postURLMax = %ld",esp_settings->postURLMax); } /********************************************************/ int32_t data_get_postToServer(void){ return postToServer; } void data_set_postToServer(int32_t val){ postToServer = val; } void data_init_postToServer(){ /*initiate postURLNumber to pointing to default server*/ if(esp_settings->postURLNumber == 0) { esp_settings->postURLNumber = 1; } postToServer = esp_settings->postURLNumber; //ESP_LOGI(TAG,"Initiate postToServer = %ld ",postToServer); } /********************************************************/ uint32_t data_get_alertInterval(){ return esp_settings->alertInterval; } /********************************************************/ void data_set_urlConnect(void) { if(TEMPSTICK_SERVER) { switch(esp_settings->postURLNumber) { case TEMPSTICK_SERVER1: sprintf(urlConnect, "%s",MCU_BASE_URL1 ); ESP_LOGI(TAG,"urlConnect server1 : %s",(char*)(&urlConnect[8])); break; case TEMPSTICK_SERVER2: sprintf(urlConnect, "%s",MCU_BASE_URL2 ); ESP_LOGI(TAG,"urlConnect server2 : %s",(char*)(&urlConnect[8])); break; case TEMPSTICK_SERVER3: sprintf(urlConnect, "%s",MCU_BASE_URL3 ); ESP_LOGI(TAG,"urlConnect server3 : %s",(char*)(&urlConnect[8])); break; } } else { sprintf(urlConnect, "%s",TESTING_SERVER_BASE_URL ); ESP_LOGI(TAG,"urlConnect test server : %s",(char*)(&urlConnect[7])); } } ======= >>>>>>> 4ea13f8 (Added azuma wifi switch backup code)