diff --git a/.cproject b/.cproject index bd5834b..b35f017 100644 --- a/.cproject +++ b/.cproject @@ -1,18 +1,31 @@ +<<<<<<< HEAD +======= + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) +<<<<<<< HEAD +======= + + + + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) \ No newline at end of file diff --git a/.project b/.project index 73a9216..3dc10af 100644 --- a/.project +++ b/.project @@ -1,6 +1,10 @@ +<<<<<<< HEAD tempstick_cellular_esp32 +======= + Azuma-wifi-switch +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/README.md b/README.md index 27ddf0d..2d7bd20 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +<<<<<<< HEAD ESP-IDF template app ==================== @@ -9,3 +10,50 @@ Please check [ESP-IDF docs](https://docs.espressif.com/projects/esp-idf/en/lates Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* +======= +**Edit a file, create a new file, and clone from Bitbucket in under 2 minutes** + +When you're done, you can delete the content in this README and update the file with details for others getting started with your repository. + +*We recommend that you open this README in another tab as you perform the tasks below. You can [watch our video](https://youtu.be/0ocf7u76WSo) for a full demo of all the steps in this tutorial. Open the video in a new tab to avoid leaving Bitbucket.* + +--- + +## Edit a file + +You’ll start by editing this README file to learn how to edit a file in Bitbucket. + +1. Click **Source** on the left side. +2. Click the README.md link from the list of files. +3. Click the **Edit** button. +4. Delete the following text: *Delete this line to make a change to the README from Bitbucket.* +5. After making your change, click **Commit** and then **Commit** again in the dialog. The commit page will open and you’ll see the change you just made. +6. Go back to the **Source** page. + +--- + +## Create a file + +Next, you’ll add a new file to this repository. + +1. Click the **New file** button at the top of the **Source** page. +2. Give the file a filename of **contributors.txt**. +3. Enter your name in the empty file space. +4. Click **Commit** and then **Commit** again in the dialog. +5. Go back to the **Source** page. + +Before you move on, go ahead and explore the repository. You've already seen the **Source** page, but check out the **Commits**, **Branches**, and **Settings** pages. + +--- + +## Clone a repository + +Use these steps to clone from SourceTree, our client for using the repository command-line free. Cloning allows you to work on your files locally. If you don't yet have SourceTree, [download and install first](https://www.sourcetreeapp.com/). If you prefer to clone from the command line, see [Clone a repository](https://confluence.atlassian.com/x/4whODQ). + +1. You’ll see the clone button under the **Source** heading. Click that button. +2. Now click **Check out in SourceTree**. You may need to create a SourceTree account or log in. +3. When you see the **Clone New** dialog in SourceTree, update the destination path and name if you’d like to and then click **Clone**. +4. Open the directory you just created to see your repository’s files. + +Now that you're more familiar with your Bitbucket repository, go ahead and add a new file locally. You can [push your change back to Bitbucket with SourceTree](https://confluence.atlassian.com/x/iqyBMg), or you can [add, commit,](https://confluence.atlassian.com/x/8QhODQ) and [push from the command line](https://confluence.atlassian.com/x/NQ0zDQ). +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index d7256b1..fbf084d 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,8 +2,13 @@ # for more information about component CMakeLists.txt files. idf_component_register( +<<<<<<< HEAD SRCS main.c uart_ifx.c port.c adc_ifx.c modem.c comms.c rtc.c i2c_sensors.c data_processing.c ota.c hmi.c wifi_Init.c wifi_Client.c wifi_OTA.c wifi_webServer.c nvm.c # list the source files of this component INCLUDE_DIRS # optional, add here public include directories +======= + SRCS main.c uart_ifx.c port.c adc_ifx.c modem.c comms.c rtc.c data_processing.c ota.c hmi.c wifi_Init.c wifi_Client.c wifi_OTA.c wifi_webServer.c nvm.c # list the source files of this component + INCLUDE_DIRS "."# optional, add here public include directories +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) PRIV_INCLUDE_DIRS # optional, add here private include directories REQUIRES driver esp_adc nvs_flash app_update esp_timer esp_event esp-tls esp_http_client esp_https_server ulp soc esp_wifi lwip mqtt# optional, list the component requirements PRIV_REQUIRES # optional, list the private requirements diff --git a/main/comms.c b/main/comms.c index a15b8ae..75f4f97 100644 --- a/main/comms.c +++ b/main/comms.c @@ -1,3 +1,4 @@ +<<<<<<< HEAD /* * comms.c * @@ -28,6 +29,29 @@ #define LOG_LOCAL_LEVEL ESP_LOG_INFO #include "esp_log.h" +======= + +#include "esp_app_desc.h" +#include "main.h" +#include "rtc.h" +#include "hmi.h" +#include "wifi_Init.h" +#include +#include +#include +#include +#include +#include "modem.h" +#include "ota.h" +#include "comms.h" +#include "wifi_Client.h" +#include "mqtt_client.h" +#include "data_processing.h" +#include "driver/gpio.h" +#include "port.h" +#include "wifi_Client.h" +#include "wifi_OTA.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) // Development support: force the operation of the following configuration functions #ifdef SET_CFG_BITS @@ -36,23 +60,64 @@ #define FORCE_MCU_PROG_DOWNLOAD 1 #define FORCE_MODEM_PROG_DOWNLOAD 1 #else +<<<<<<< HEAD +======= + + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define FORCE_MCU_CONFIG_DOWNLOAD 0 #define FORCE_MCU_PROG_DOWNLOAD 0 #define FORCE_MODEM_PROG_DOWNLOAD 0 #endif +<<<<<<< HEAD /* Set 1 to use "unwired/[IMEI]", e.g. "unwired/862061049756488" +======= +/* Set 1 to use "unwired/[IMEI]", e.g. "unwired/862061049756488" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) * Set 0 to use "unwiredct" */ #define COMMS_PUBLISH_WITH_IMEI 0 #define JWT_LEN 1024 +<<<<<<< HEAD //#define MCU_SP4_URL "https://parthasarathimishra.com/hae/tempstick/%s/mcu_config_download/" /* Name of file to create in modem file system for the downloaded image. +======= +#define CUSTOMER_SERVER 1 +#define TESTING_SERVER 0 +#define NEW_SERVER 0 + +#define COMMS_TIMER_ID 1 +#define OTA_STATUS_OK 0 + +#if CUSTOMER_SERVER +/* definitions */ +/*For developement: dev.api.mywirelessfence.com*/ +/*For production: api.mywirelessfence.com*/ +#define SERVER_URL_BASE "https://api.mywirelessfence.com/api/v1/trackers/tracker/%s/" //Partha - March 16, 2022 +#define UPDATE_URL SERVER_URL_BASE "update" +//#define MCU_CONFIG_URL "https://api.mywirelessfence.com/api/v2/trackers/tracker/%s/mcu_config_download" //Partha - March + +/*customer (Laxmana's endpoint)*/ +#define MCU_CONFIG_URL "https://ops.azuma.com/SMSListener/api/DeviceInfo/%s/update" + +/*customer (Laxmana's endpoint)*/ +#define MCU_SP4_URL "http://54.204.230.201:8081/hae/azuma/%s/mcu_config_download" + +/*customer endpoint*/ +#define MCU_SP5_URL "http://54.204.230.201:8081/hae/azuma/%s/mcu_pgm_download/version" + +/*customer endpoint*/ +#define MCU_SP6_URL "https://ops.azuma.com/SMSListener/api/DeviceInfo/%s/modem_pgm_download/version" + +/* Name of file to create in modem file system for the downloaded image. +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) * This is arbitrary, but we name the upper and lower version differently * to avoid possible mixing up at the firmware level (the server can * still mix them up if a lower app was put at the /higher URL) @@ -64,6 +129,7 @@ #define MCU_FW_UPDATE_FILE "lrsm0005_fw_ota_image_higher.bin" #endif +<<<<<<< HEAD //#define MCU_FW_BIN_FILE_URL1_HIGHER "https://parthasarathimishra.com/hae/azuma/%s/mcu_pgm_download/lrsm0005_fw_ota_image_higher.bin" //#define MCU_FW_BIN_FILE_URL1_LOWER "https://parthasarathimishra.com/hae/azuma/%s/mcu_pgm_download/lrsm0005_fw_ota_image_lower.bin" #define MCU_PROG_VER_URL SERVER_URL_BASE "mcu_pgm_download/version" @@ -80,11 +146,37 @@ #define MQTT_PUB_TOPIC_LEN 48 +======= +//#define MODEM_FW_UPDATE_FILE "Update_BG77LAR02A04_01.009.01.009-R02A04_01.006.01.006.zip" +//#define MCU_PROG_URL_HIGHER "https://parthasarathimishra.com/hae/azuma/%s/mcu_pgm_download/lrsm0005_fw_ota_image_higher.bin" +//#define MCU_PROG_URL_LOWER "https://parthasarathimishra.com/hae/azuma/%s/mcu_pgm_download/lrsm0005_fw_ota_image_lower.bin" +#define MCU_PROG_VER_URL SERVER_URL_BASE "mcu_pgm_download/version" +//#define MODEM_PROG_URL SERVER_URL_BASE "modem_pgm_download" +#define MODEM_PROG_VER_URL SERVER_URL_BASE "modem_pgm_download/version" +#define WHITELIST_URL SERVER_URL_BASE "whitelist" + +/*Laxmana's server*/ +#define MCU_PROG_URL "https://ops.azuma.com/CSW/HAEMcuUpdates/New/" MCU_FW_UPDATE_FILE +//#define MODEM_PROG_URL "https://parthasarathimishra.com/hae/azuma/%s/modem_pgm_download/Update_BG77LAR02A04_01.009.01.009-R02A04_01.006.01.006.zip" +/*Laxmana's server*/ +#define MODEM_PROG_URL "https://ops.azuma.com/CSW/HAEModemUpdates/New/Update_BG77.bin" + +/*customer endpoint*/ +#define MQTT_HOST "azumamqtt1.cedalo.cloud" +#define MQTT_PORT 1883 +#endif + +#define MQTT_CLIENTID (BG96_deviceID) // TODO: Put ESP MAC ID here + +/* "unwired/862061049756488" (modem's IMEI) */ +#define MQTT_PUB_TOPIC_LEN 48 +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define MCU_CONFIG_FLAG_WHITELIST_UPDATE 0x1 #define MCU_CONFIG_FLAG_MCU_UPDATE 0x2 #define MCU_CONFIG_FLAG_MODEM_UPDATE 0x4 +<<<<<<< HEAD #define HTTP_RETRY_COUNT_MAX 5 #define HTTP_POST_RETRY_MAX 2 #define HTTP_RETRY_WAIT 20000 @@ -103,6 +195,96 @@ int qmtopen_retries = 0; #define QMTOPEN_RETRY_NUM 3 /// mqtt added end /// +======= +#define HTTP_RETRY_COUNT 5 +#define HTTP_RETRY_WAIT 20000 + +#define HOURS_TO_SECONDS_COEFF 3600 + +#define HEARTBEAT_TIME_SEC 14400 +#define HEARTBEAT_TIME_RST 5 + +static const char* TAG = "COMMS"; + +#define LOG_LOCAL_LEVEL ESP_LOG_INFO + +#define STATUS_ERROR -1 + +#define MCU_OTA_FILE_LOCAL "OTA.bin" + +#define RELAY_ON 1 +#define RELAY_OFF 0 + + +extern bool isTestMode; +extern int heartbeat_time; +extern int qmtopen_retries; +extern bool qmtopen_fail; +#define QMTOPEN_RETRY_NUM 3 +extern bool qmtclose_fail; +extern bool cops_fail; +extern bool testmode_timeout; + +static int cops_reset_num = 0; + +bool deviceCfged = false; + +int config_heartbeat_time = HEARTBEAT_TIME_SEC; + +bool WakeupFlag = false; + +bool ConfigFlag = false; + +bool McuUpdateFlag = false; + +bool ModemUpdateFlag = false; + +bool PreviousRelayState = false; + +bool RelayState = false; + +char time_stamp_str[50]; + +char mac_address[16]; + +char SP1[150]; + +char board_version_no[3]={'0'}; + +//#define BROCKER_URL_TEST "mqtt://azumamqtt1.cedalo.cloud:1883" +#define BROCKER_URL_TEST "mqtt://broker.mqtt.cool:1883" +#define MQTT_TOPIC_PUB "/topic/qos0" +#define MQTT_TOPIC_SUB "/topic/qos0" + +esp_mqtt_client_handle_t client; + + + // Configure Target brocker URL + esp_mqtt_client_config_t mqtt_cfg = { + .broker.address.uri = BROCKER_URL_TEST, + }; + +void SP1_Mqtt_Tx(int ); + + +/* This function will handle led state depending on previous relay state. +*/ +static void update_relay_led() +{ + if(PreviousRelayState == true) + { + //board_led_all_off(); + //board_led_green_on(); + hmi_choose_led(HMI_LED_GREEN, HMI_LED_ON); + } + else + { + //board_led_all_off(); + //board_led_red_on(); + hmi_choose_led(HMI_LED_RED, HMI_LED_ON); + } +} +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) typedef enum { @@ -116,6 +298,7 @@ typedef enum typedef enum { COMMS_STATE_INIT, +<<<<<<< HEAD COMMS_STATE_WAIT_MODEM, COMMS_STATE_WAIT_NET_CONNECT, COMMS_STATE_WIFI_CONNECT, @@ -134,11 +317,23 @@ typedef enum COMMS_STATE_WAIT_HTTP_GET_SP6, COMMS_STATE_WAIT_HTTP_GET_MODEM_UPDATE, /* Get modem update version */ COMMS_STATE_WAIT_MODEM_UPDATE, /* Wait for modem to do its thing */ +======= + COMMS_STATE_WAIT_WIFI, + COMMS_STATE_WAIT_NET_CONNECT, + COMMS_STATE_WAIT_MQTT_CONNECT, + COMMS_STATE_WAIT_MQTT_PUB, + COMMS_STATE_WAIT_MQTT_CLOSE, + COMMS_STATE_WAIT_HTTP_SEND_SP3, + COMMS_STATE_WAIT_HTTP_GET_SP3, + COMMS_STATE_WAIT_HTTP_SEND_SP4, + COMMS_STATE_WAIT_HTTP_GET_SP4, +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE, /* Get version */ COMMS_STATE_WAIT_HTTP_GET_MCU_FILE, /* Download file */ COMMS_STATE_WAIT_MCU_UPDATE, /* Install update */ COMMS_STATE_GOING_IDLE, COMMS_STATE_IDLE, +<<<<<<< HEAD COMMS_STATE_WAIT, COMMS_STATE_WAIT_MODEM_OFF, @@ -147,6 +342,16 @@ typedef enum typedef int (*comms_switch_cb)(comms_state_t init_state, const char* url,const char* msg, comms_state_t success_state); +======= + //COMMS_STATE_RELAY_WAIT, + COMMS_STATE_WAIT, + COMMS_STATE_WAIT_HTTP_SEND_SP5, + COMMS_STATE_WAIT_HTTP_GET_SP5, + COMMS_STATE_WAIT_BG96_OFF, + +} comms_state_t; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) typedef struct { comms_state_t state; @@ -159,7 +364,11 @@ typedef struct bool is_starting; /* User connect callback */ +<<<<<<< HEAD comms_op_cb_t connect_cb; +======= + comms_op_cb_t connect_cb; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) char mqtt_pub_topic[MQTT_PUB_TOPIC_LEN]; /* Printing an SP2 message: @@ -179,7 +388,11 @@ typedef struct bool get_mcu_update; bool get_modem_update; +<<<<<<< HEAD /* Status of the last communication cycle +======= + /* Status of the last communication cycle +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) * OK or ERROR */ int last_cycle_status; @@ -187,11 +400,16 @@ typedef struct /* Status of last pending operation */ bool last_op_success; bool wf1_msg; +<<<<<<< HEAD +======= + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) int httpRetryCnt; comms_state_t http_init_state; } comms_t; +<<<<<<< HEAD /* Unique timer ID for this process for use with timer module */ //#define COMMS_TIMER_ID 1 esp_timer_handle_t comms_timer; @@ -218,12 +436,173 @@ char http_post_header[250]; #if (FAKE_NETWORK == 1) char server_resp[] = "{\"request\":\"settings\",\"id\":10608508,\"minTemp\":-1.11,\"maxTemp\":26.67,\"minHum\":10,\"maxHum\":80,\"voltageQuit\":2.3,\"alertInterval\":900,\"sendInterval\":60,\"sendDetails\":1,\"postURLNumber\":2,\"postURLMax\":3,\"tmpThA_GP\":71.11,\"tmpThA_GN\":70,\"tmpThB_GP\":71.11,\"tmpThB_GN\":70,\"tmpThC_GP\":71.11,\"tmpThC_GN\":70,\"tmpThD_GP\":-44.44,\"tmpThD_GN\":-45.56,\"tmpThE_GP\":-44.44,\"tmpThE_GN\":-45.56,\"tmpThF_GP\":-44.44,\"tmpThF_GN\":-45.56,\"T_TKN\":5,\"humThA_GP\":103,\"humThA_GN\":101,\"humThB_GP\":103,\"humThB_GN\":101,\"humThC_GP\":103,\"humThC_GN\":101,\"humThD_GP\":-1,\"humThD_GN\":-3,\"humThE_GP\":-1,\"humThE_GN\":-3,\"humThF_GP\":-1,\"humThF_GN\":-3,\"H_TKN\":5,\"TC_M\":1,\"TC_TYPE\":\"K\",\"tcThA_GP\":71.11,\"tcThA_GN\":70,\"tcThB_GP\":71.11,\"tcThB_GN\":70,\"tcThC_GP\":71.11,\"tcThC_GN\":70,\"tcThD_GP\":-168.33,\"tcThD_GN\":-169.44,\"tcThE_GP\":-168.33,\"tcThE_GN\":-169.44,\"tcThF_GP\":-168.33,\"tcThF_GN\":-169.44,\"TC_TKN\":5,\"LT_M\":3,\"LT_LVLGP\":200,\"LT_LVLGN\":50,\"LT_LOCK\":900,\"LT_TKN\":5,\"AC_M\":1,\"AC_LVL\":15000,\"AC_INT\":60,\"AC_LOCK\":60,\"AC_TKN\":5,\"PWR_M\":3,\"PWR_DBNC\":60,\"PWR_TKN\":5,\"PUSH_TKN\":5,\"TKN_RLD\":300}"; #endif +======= +/* Local process state */ + + +static comms_t comms; +uint8_t Comms_WF1_Flag = 2; //Partha - 22 March, 2022 +//extern void Bypass_Comms_Interval(uint8_t state); +extern void Copy_ScanData(void *src); + +//declaration of Comms_Check_TestMode. + +static void Comms_Check_TestMode(); + + +/* ------------------------------------------------------------------------- */ + +/* Comms process: + * 1. Get info from server via HTTP command sequence. + * 2. Publish SP1 record: device status. + * 3. Publish SP2 records: BLE scan data. Each record is one scan event. + */ + + +/* Record format + * + * To server: + * TYPE IMEI TIMESTAMP ... EP + * + * Fields are delineated by spaces. Data items within fields must use a comma delineator. + * + * Type: SP1 SP2 ... SPN + * + * Timestamp: epoch time, seconds + * E.g. 1599492628 + * + * SP1 fields: + * 1. Firmware version : string, e.g. v1.2.1-5f1ec90 + * 2. battery level : int mV reading + * 3. LTE RSSI : int dB + * + * SP1 862061049756488 1599777618 v1.2.1-5f1ec90 3650 -82 EP + * + * SP2 fields: + * 1 Epoch of scan : int + * 2 Array of SCAN_DATA[max 20] where + * SCAN_DATA: + * UUID,MAJOR,MINOR,BLE-RSSI + * UUID : hex string + * MAJOR: hex string + * MINOR: hex string + * RSSI : int dB + * + * Full uplink record example containing 3 SCAN DATA items: + * SP2 862061049756488 1599777618 1599775427 ABCD0123ABCD0123,ABCD,0123,-77 ABCD0123ABCD0123,ABCD,0124,-57 ABCD0123ABCD0123,ABCD,0125,-72 EP + * + * Testing: + * mosquito_pub + * -h 54.90.145.32 + * -m "SP2 862061049756488 1599777618 1599775427 ABCD0123ABCD0123,ABCD,0123,-77 ABCD0123ABCD0123,ABCD,0124,-57 ABCD0123ABCD0123,ABCD,0125,-72 EP" + * -t unwired/862061049756488 + * -i 862061049756488 + */ + + +/* +static int get_int_arg(void) +{ + char* p = strtok(0, " "); + int arg = CONFIG_BAD_INT_VALUE; + if (p) + { + arg = atoi(p); + } + return arg; +} +#*/ +/* +static uint32_t get_hex_arg(void) +{ + char* p = strtok(0, " "); + uint32_t arg = CONFIG_BAD_HEX_VALUE; + if (p) + { + arg = strtol(p, 0, 16); + } + return arg; +} +*/ + +static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { + event_id = 0; + if (event_base == WIFI_EVENT) { + switch (event_id) { + case WIFI_EVENT_STA_START: + ESP_LOGI(TAG, "Wi-Fi started, connecting..."); + esp_wifi_connect(); + break; + + case WIFI_EVENT_STA_CONNECTED: + ESP_LOGI(TAG, "Wi-Fi connected."); + break; + + case WIFI_EVENT_STA_DISCONNECTED: + ESP_LOGW(TAG, "Wi-Fi disconnected, reconnecting..."); + esp_wifi_connect(); + break; + + default: + ESP_LOGI(TAG, "Unhandled Wi-Fi event: %ld", event_id); + break; + } + } + else if (event_base == IP_EVENT) { + switch (event_id) { + case IP_EVENT_STA_GOT_IP: { + ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; + ESP_LOGI(TAG, "Got IP: " IPSTR, IP2STR(&event->ip_info.ip)); + break; + } + } + } +} + + +static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) +{ + ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%" PRIi32 "", base, event_id); + esp_mqtt_event_handle_t event = event_data; + esp_mqtt_client_handle_t client = event->client; + + switch ((esp_mqtt_event_id_t)event_id) { + case MQTT_EVENT_CONNECTED: + ESP_LOGI(TAG, "MQTT Connected!"); + comms.poll_timer = true; + break; + case MQTT_EVENT_PUBLISHED: + ESP_LOGI(TAG, "MQTT Message Published!"); + comms.poll_timer = true; + break; + case MQTT_EVENT_DISCONNECTED: + ESP_LOGI(TAG, "MQTT Broker Disconnected!"); + comms.poll_timer = true; + break; + + case MQTT_EVENT_DATA: + ESP_LOGI(TAG, "Received on topic: %.*s, Message: %.*s", event->topic_len, event->topic, event->data_len, event->data); + ESP_LOGI(TAG, "string copy start"); + char tmp[20] = {0}; // Ensure it's properly initialized + strncpy(tmp, event->data, sizeof(tmp) - 1); // Copy message safely + ESP_LOGI(TAG, "string copy value : %s",tmp); + ESP_LOGI(TAG, "string copy end"); + comms.poll_timer = true; + break; + + default: + break; + } +} + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* ------------------------------------------------------------------------- */ static const char* state_str(comms_state_t s) { switch (s) { case COMMS_STATE_INIT:return "INIT"; +<<<<<<< HEAD case COMMS_STATE_WAIT_MODEM:return "WAIT_MODEM"; case COMMS_STATE_WAIT_NET_CONNECT:return "WAIT_NET_CONNECT"; case COMMS_STATE_WIFI_CONNECT:return "WIFI_CONNECT"; @@ -249,11 +628,28 @@ static const char* state_str(comms_state_t s) case COMMS_STATE_IDLE:return "IDLE"; case COMMS_STATE_WAIT:return "STATE_WAIT"; case COMMS_STATE_WAIT_MODEM_OFF:return "WAIT_MODEM_OFF"; +======= + case COMMS_STATE_WAIT_WIFI:return "WAIT_WIFI"; + case COMMS_STATE_WAIT_NET_CONNECT:return "WAIT_NET_CONNECT"; + case COMMS_STATE_WAIT_MQTT_CONNECT:return "WAIT_MQTT_CONNECT"; + case COMMS_STATE_WAIT_MQTT_PUB:return "WAIT_MQTT_PUB"; + case COMMS_STATE_WAIT_MQTT_CLOSE:return "WAIT_MQTT_CLOSE"; + case COMMS_STATE_WAIT_HTTP_SEND_SP3:return "WAIT_HTTP_SEND_CONFIG_STATUS"; + case COMMS_STATE_WAIT_HTTP_GET_SP3:return "WAIT_HTTP_GET_CONFIG_STATUS"; + case COMMS_STATE_WAIT_HTTP_SEND_SP4:return "WAIT_HTTP_SEND_MCU_CONFIG"; + case COMMS_STATE_WAIT_HTTP_GET_SP4:return "WAIT_HTTP_GET_MCU_CONFIG"; + case COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE:return "WAIT_HTTP_GET_MCU_UPDATE"; + case COMMS_STATE_WAIT_HTTP_GET_MCU_FILE:return "WAIT_HTTP_GET_MCU_FILE"; + case COMMS_STATE_WAIT_MCU_UPDATE:return "WAIT_MCU_UPDATE"; + case COMMS_STATE_GOING_IDLE: return "COMMS_STATE_GOING_IDLE"; + case COMMS_STATE_IDLE:return "IDLE"; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) default: return ""; } } +<<<<<<< HEAD static esp_err_t build_http_headerBodyMsg(uint32_t len) { /* jsonMessage address is the same address as msg*/ @@ -288,10 +684,19 @@ static esp_err_t build_http_headerBodyMsg(uint32_t len) static void transition(comms_state_t state_to) { ESP_LOGD(TAG,"%s->%s\n", state_str(comms.state), state_str(state_to)); +======= +static void transition(comms_state_t state_to) +{ + + ESP_LOGI(TAG, "Transistion function "); + ESP_LOGD(TAG, "%s->%s\n", state_str(comms.state), state_str(state_to)); + ESP_LOGI(TAG, "%s->%s\n", state_str(comms.state), state_str(state_to)); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) comms.state = state_to; } +<<<<<<< HEAD /* These handlers handle completion events for commands issued by the BG96 modem driver. * If success, the comms process continues by way of a "timer" event. * If fail, the comms process stops what it was doing and goes back to "idle" state. @@ -779,12 +1184,49 @@ static int start_http_get_request(comms_state_t init_state,const char* url, cons } //Unable to connect to LTE network } +======= +static int start_mqtt_publish_sequence(void) //Partha - March 11, 2022 +{ + /* We have synchronized the configuration + * trigger the start completed event if we were starting. + */ + if (comms.is_starting) { + comms.is_starting = false; + if (comms.start_cb) { + comms.start_cb(COMMS_STATUS_OK); + comms.start_cb = 0; + } + } + + /* Reset the operation status flag */ + comms.last_op_success = false; + + + + /* Run the MQTT publish sequence */ + int retval = 0; + retval = esp_mqtt_client_start(client); /*Mqtt client connect */ + // SP1_Mqtt_Tx(config_heartbeat_time); + + if (retval == WIFI_STATUS_OK) + { + /* Indicate offloading data, moved to BG96 init for TFS-7 */ + //hmi_set_offload_mode(true); + ESP_LOGI(TAG,"Connecting to MQTT broker\r\n"); + transition(COMMS_STATE_WAIT_MQTT_CONNECT); + } + else + { + ESP_LOGE(TAG, "Connecting to MQTT broker failed.\r\n"); + comms.poll_timer = true; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) transition(COMMS_STATE_GOING_IDLE); } return retval; } +<<<<<<< HEAD static int start_http_post_request(comms_state_t init_state,const char* url, const char* message, comms_state_t success_state) { esp_err_t ret; @@ -926,6 +1368,8 @@ static void fwupd_op_cb(int status) * Be mindful of the return values and feed them back to the updater engine. * */ +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static int ota_file_open_cb(uint32_t fileSize) { @@ -963,6 +1407,7 @@ static int ota_file_data_cb(const char* buf, int buf_len) return retval; } +<<<<<<< HEAD static int sum_digits(int digit) { int sum = 0; @@ -1144,12 +1589,476 @@ static void Comms_Parse_SP5(char *buf, int len) ESP_LOGI(TAG,"GET MCU UPDATE"); comms.poll_timer = true; transition(COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE); +======= +/** +This function is used to check if MAC has correct length (15) +to check if the parsed MAC is same as hardware MAC +*/ +static bool mac_check_valid(char *message_mac) +{ + //find the length of message imei + int len = strlen(message_mac); + ESP_LOGI(TAG, "Parsed MAC : %s\r\n",message_mac); + + //check length of MAC field + if (len != 15){ + //invalid IMEI + ESP_LOGW(TAG, "Invalid MAC length"); + return false; + } + + if(!strcmp(message_mac, MAC_ID)){ + ESP_LOGI(TAG,"Message MAC matches device MAC\r\n"); + return true; + } + else{ + ESP_LOGW(TAG, "Message MAC doesn't match device MAC\r\n"); + return false; + } +} + + +/* These handlers handle completion events for commands issued by the BG96 modem driver. +* If success, the comms process continues by way of a "timer" event. +* If fail, the comms process stops what it was doing and goes back to "idle" state. +* The comms process is started once at startup and does not stop thereafter. +*/ +static void wifi_event_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* started */ + transition(COMMS_STATE_WAIT_NET_CONNECT); + } + else + { + /* Nope - back to init */ + ESP_LOGW(TAG, "WiFi startup failed.\r\n"); + transition(COMMS_STATE_GOING_IDLE); + } +} + +static void net_connect_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* connected */ + } + else + { + /* Nope - back to init */ + ESP_LOGW(TAG, "Network connection failed.\r\n"); + if(cops_fail){ + + transition(COMMS_STATE_GOING_IDLE); + } + else{ + transition(COMMS_STATE_GOING_IDLE); + } + } + update_relay_led(); +} + +static void mqtt_pub_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* connected */ + } + else + { + + /* Nope - back to idle */ + ESP_LOGW(TAG,"MQTT publish failed.\r\n"); + transition(COMMS_STATE_GOING_IDLE); + + } + update_relay_led(); +} + + +static void mqtt_close_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* connected */ + } + else + { + if(qmtopen_fail){ + if(qmtopen_retries >= QMTOPEN_RETRY_NUM){ + qmtopen_retries = 0; + qmtopen_fail = false; + ESP_LOGI(TAG,"MQTT open retries exceeded. bypass SP1\r\n"); + transition(COMMS_STATE_WAIT_MQTT_CLOSE); + } + else{ + qmtopen_fail = false; + ESP_LOGW(TAG,"MQTT close failed.\r\n"); + transition(COMMS_STATE_WAIT_NET_CONNECT); + } + } + + + } +} + +static void mqtt_connect_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* connected */ + } + else + { + /* Nope - back idle */ + ESP_LOGW(TAG,"MQTT connection failed.\r\n"); + + /*if open fail flag is set then mqtt connection is closed + and then attempt another mqtt sequence*/ + if(qmtopen_fail){ + //qmtopen_fail = false; + ESP_LOGI(TAG,"Closing connection\r\n"); + //GPIO_ResetBits(GPIO_Pin_22); + //heartbeat_time = 5; + transition(COMMS_STATE_WAIT_MQTT_PUB); + } + else{ + transition(COMMS_STATE_GOING_IDLE); + } + } + + + update_relay_led(); +} + +static void http_op_cb(int status) +{ + if (WIFI_STATUS_OK == status) + { + /*Connected. Set the poll_timer to be true*/ + comms.poll_timer = true; + } + else + { + /*If not connected then check the number of http retries if it's greater than zero*/ + if(comms.httpRetryCnt) + { + /*decrement the number of retries by 1*/ + comms.httpRetryCnt--; + + /*start a timer for 20sec*/ + // timer_start(COMMS_TIMER_ID,HTTP_RETRY_WAIT); + + /*Logging waiting message*/ + ESP_LOGI(TAG,"Waiting for another HTTP Retry.\r\n"); + + /*transition to COMMS_STATE_WAIT state*/ + transition(COMMS_STATE_WAIT); + } + else + { + /*Reinitialize the counter of http retries with 3*/ + comms.httpRetryCnt = HTTP_RETRY_COUNT; + + /*Set the poll_timer to be true*/ + comms.poll_timer = true; + + /* Nope - back to idle */ + ESP_LOGW(TAG,"HTTP operation failed.\r\n"); +/* =======_send SP1 message with the count field as 'F'_=======*/ + //uint8_t heartbeat_time = 1 ; + + SP1_Mqtt_Tx(heartbeat_time); //creating sp1 message + int retval = start_mqtt_publish_sequence(); /* Run the MQTT publish sequence if nothing else pending */ + if(WIFI_STATUS_OK==retval) + { + ESP_LOGI(TAG,"MQTT Publish SP1 message success"); + } + else + { + ESP_LOGI(TAG,"MQTT Publish SP1 message failed"); + + + } + /*transition to COMMS_STATE_GOING_IDLE state*/ + transition(COMMS_STATE_GOING_IDLE); + + } + } + update_relay_led(); +} + +static void fotadl_op_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* completed. */ + ESP_LOGI(TAG,"Modem upgrade SUCCESS.\r\n"); + } + else + { + /* failed. */ + ESP_LOGW(TAG,"Modem upgrade FAILED.\r\n"); + } + /* Let state handle it */ +} + +static int start_http_get_request(comms_state_t init_state,const char* url, const char* log_msg, comms_state_t success_state) +{ + /* Reset the operation status flag */ + comms.last_op_success = false; + /* Initialize the comms.http_init_state to init_state */ + comms.http_init_state = init_state; +// char mac_str[15]; + /* Now make the GET request. */ + /* Setup URL */ + memset(comms.mqtt_buf, 0, sizeof(comms.mqtt_buf)); + snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), url, MAC_ID); + ESP_LOGI(TAG,"URL %s\r\n", comms.mqtt_buf); + /* Download the GET data to modem */ + int retval = -1; + char temp[512] = {0}; + retval = http_client_get((const char*)comms.mqtt_buf,temp); + + ESP_LOGI(TAG,"GET %s\r\n", temp); + + + if (retval == WIFI_STATUS_OK) + { + // clear_reset_timestamp(); TODO: Track reset & clear it here + ESP_LOGI(TAG,"GET %s\r\n", log_msg); + comms.poll_timer = true; + transition(success_state); + } + else + { + ESP_LOGE(TAG, "GET %s failed.\r\n", log_msg); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + return retval; +} + +static void fwdl_op_cb(int status) +{ + + + if (WIFI_STATUS_OK == status) + { + /* Firmware file was downloaded to the modem. */ + ESP_LOGI(TAG,"MCU FW download SUCCESS.\r\n"); + + comms.last_op_success = true; + /* Continue in the current state */ + comms.poll_timer = true; + } + else + { + if(comms.httpRetryCnt) + { + /*decrement the number of retries by 1*/ + comms.httpRetryCnt--; + + /*start a timer for 20sec*/ + // timer_start(COMMS_TIMER_ID,HTTP_RETRY_WAIT); + + /*Logging waiting message*/ + ESP_LOGI(TAG,"Waiting for another HTTP Retry.\r\n"); + + /*transition to COMMS_STATE_WAIT state*/ + transition(COMMS_STATE_WAIT); + } + else + { + /*Reinitialize the counter of http retries with 3*/ + comms.httpRetryCnt = HTTP_RETRY_COUNT; + + /*Set the poll_timer to be true*/ + comms.poll_timer = true; + + /* Nope - back to idle */ + /* Firmware file not downloaded. */ + ESP_LOGW(TAG,"MCU FW download operation failed.\r\n"); + /* =======_send SP1 message with the count field as 'F'_=======*/ + uint8_t heartbeat_time = 1 ; + SP1_Mqtt_Tx(heartbeat_time); //creating sp1 message + int retval = start_mqtt_publish_sequence(); /* Run the MQTT publish sequence if nothing else pending */ + if(WIFI_STATUS_OK==retval) + { + ESP_LOGI(TAG,"MQTT Publish SP1 message success"); + } + else + { + ESP_LOGI(TAG,"MQTT Publish SP1 message failed"); + } + + comms.last_op_success = false; + + /*transition to COMMS_STATE_GOING_IDLE state*/ + transition(COMMS_STATE_GOING_IDLE); + } + } +} + +static void fwupd_op_cb(int status) +{ + comms.poll_timer = true; + if (WIFI_STATUS_OK == status) + { + /* Firmware file was installed into device. */ + ESP_LOGI(TAG,"MCU FW update SUCCESS.\r\n"); + + comms.last_op_success = true; + } + else + { + /* Firmware file not installed. */ + ESP_LOGW(TAG,"MCU FW installation failed.\r\n"); + comms.last_op_success = false; + /* Restore the LED status */ + update_relay_led(); + transition(COMMS_STATE_GOING_IDLE); + } +} + +//function to prepare SP1, loads the MQTT TX buffer +void SP1_Mqtt_Tx(int config_heartbeat_time){ + + //char relay_state[3]; + //rtc_timestamp_t* gettime; + char build_version[60]={'0'}; + + + char* ptr_version = NULL; + + //create the SP1 message + //SP1 IMEI F/W VER DATE_TIME SENS_EN HEARTBEAT_TIME TEST MODE COUNT RSSI EP format + get_time(time_stamp_str, sizeof(time_stamp_str)); // Pass buffer to function + ESP_LOGI(TAG, "Time_Date : %s", time_stamp_str); + + // Get firmwae version + strcpy(build_version,BUILD_VERSION_STRING); + + ptr_version = strstr(build_version,"_v"); + strncpy(board_version_no,ptr_version + 2,3); + + // wifi_get_mac_addr(mac_address); + + if(PreviousRelayState == 1){ + sprintf(SP1,"SP1 %s %s %s %d H_%d T_%d %s %d EP",MAC_ID,BUILD_VERSION_STRING,time_stamp_str,PreviousRelayState,(config_heartbeat_time / HOURS_TO_SECONDS_COEFF) ,isTestMode,"ON",(HTTP_RETRY_COUNT-comms.httpRetryCnt)); + } + else{ + sprintf(SP1,"SP1 %s %s %s %d H_%d T_%d %s %d EP",MAC_ID,BUILD_VERSION_STRING,time_stamp_str,PreviousRelayState,(config_heartbeat_time / HOURS_TO_SECONDS_COEFF) ,isTestMode,"OFF",(HTTP_RETRY_COUNT-comms.httpRetryCnt)); + } + + ESP_LOGI(TAG, "SP1 message :%s\r\n",SP1); + + //copy sp1 message in mqtt buffer + strcpy(comms.mqtt_buf,SP1); + +} + + +/* function for parsing SP5 message */ +// format example + +static void Comms_Parse_SP5(char *buf, int len) +{ + char messageheader[4] = {0}; + char messageMAC[16] = {0}; + char timestamp[30] = {0}; //array to store the timestamp from sp5 message + char firmware_version[11] = {0}; //array to store the firmware_version from sp5 message + char *strret = NULL; //temporary pointer to store the address of the searched string (to store the returned address from strstr fn ) + float new_fw_version = 0; + float current_fw_version = 0; + char epcheck[2] = {0}; + int ret_sp5 = STATUS_ERROR; + + strret = strtok(buf, " "); + strcpy(messageheader, strret); + ESP_LOGI(TAG, "%s message is received \r\n",messageheader); + + while(strret != NULL){ + + strret = strtok (NULL," "); + strcpy(messageMAC, strret); + + ret_sp5 = mac_check_valid(messageMAC); + if(ret_sp5 != false){ + //ok IMEI + ESP_LOGI(TAG, "Fetched MAC matches board.\r\n"); + } + else{ + ESP_LOGW(TAG, "INVALID MAC!!\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + //return ret_sp5; + } + + strret = strtok (NULL," "); + strcpy(timestamp, strret); + ESP_LOGI(TAG,"Time Stamp : %s\r\n",timestamp); + + strret = strtok(NULL, "FW_ "); + + strcpy(firmware_version,strret); + + if((isdigit((unsigned char)firmware_version[0]) > 0) && (isdigit((unsigned char)firmware_version[2]) > 0)){ + /*if the MCU version string is numeric proceed*/ + /*update the version value*/ + new_fw_version = atof(firmware_version); + } + else{ + /*keep the board version as the new version so that update is not triggered*/ + ESP_LOGI(TAG,"NOT VALID FETCHED MCU FW VERSION VALUE!! \r\n"); + new_fw_version = atof(board_version_no); + } + + + current_fw_version = atof(board_version_no); + + strret = strtok (NULL," "); + strcpy(epcheck, strret); + + if(!strcmp(epcheck,"EP\"") || !strcmp(epcheck,"EP")){ + ESP_LOGI(TAG,"(%s) %s message is terminated\r\n", epcheck,messageheader); + break; + } + else{ + ESP_LOGI(TAG,"(%s) %s message is not terminated!! \r\n", epcheck,messageheader); + } + + } + + // new_fw_version = 1; + + if(!(new_fw_version > current_fw_version)) + { + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + else + { + /*Logging/printing this message*/ + ESP_LOGI(TAG,"F/W Update NEEDED \r\n"); + ESP_LOGI(TAG,"GET MCU UPDATE \r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*reading OTA files*/ } } +<<<<<<< HEAD /* function for parsing SP6 message */ // format example /*SP6 IMEI epoch T FW_V EP */ @@ -1291,12 +2200,447 @@ esp_err_t comms_http_request(comms_switch_cb cb,comms_state_t init_state, const /* ------------------------------------------------------------------------- */ +======= +/* function to parsing SP4 message */ +// format example +//SP4 862061049734352 2022/10/20_13:10_4 1 H_1 T_0 EP +static int Comms_Parse_SP4(char *buf, int len) +{ + char messageheader[4] = {0}; + char timestamp[18] = {'0'}; + char messageMAC[16] = {'0'}; + char testMode[3] = {'0'}; + //bool relayState = false; +// char* relayStatePtr = NULL; + int sp4_ret = STATUS_ERROR; + char* strret = NULL; + char hbeat[5] = {'0'}; +// char temp[5] = {'0'}; + char epcheck[2] = {0}; + + strret = strtok(buf," "); + strcpy(messageheader, strret); + ESP_LOGI(TAG,"%s message is received \r\n",messageheader); + + while(strret != NULL){ + strret = strtok (NULL," "); + strcpy(messageMAC, strret); + + sp4_ret = mac_check_valid(messageMAC); + if(sp4_ret != false){ + //ok IMEI + ESP_LOGI(TAG, "Fetched MAC matches board.\r\n"); + } + else{ + ESP_LOGW(TAG, "INVALID MAC!!\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + return sp4_ret; + } + + + /*Parse string for date/time*/ + strret = strtok (NULL," "); + strcpy(timestamp, strret); + ESP_LOGI(TAG,"Time Stamp : %s\r\n",timestamp); + + strret = strtok (NULL," "); + if(strret[0] == '1'){ + RelayState = true; + } + else + { + RelayState = false; + } + + ESP_LOGI(TAG,"Relay State : %d\r\n",RelayState); + + strret = strtok (NULL," "); + strcpy(hbeat, strret+2); + ESP_LOGI(TAG,"Received Heartbeat Time : %s\r\n",hbeat); + config_heartbeat_time = atoi(hbeat); + + strret = strtok(NULL," "); + strcpy(testMode, strret); + if(testMode[2] == '1') + { + if(testmode_timeout){ + isTestMode = false; + testmode_timeout = false; + } + else{ + isTestMode = true; + } + + } + else + { + isTestMode = false; + } + //===================================== + ESP_LOGI(TAG,"Test Mode: %d\r\n",isTestMode); + //_____________________ + //maximum heartbeat time is 4 days (96 hours) + if((config_heartbeat_time != 0) && (config_heartbeat_time < 97 && config_heartbeat_time > 0)){ + ESP_LOGI(TAG,"Valid fetched Heartbeat time value\r\n"); + config_heartbeat_time *= HOURS_TO_SECONDS_COEFF; + deviceCfged = true; + } + else{ + config_heartbeat_time = HEARTBEAT_TIME_SEC; + deviceCfged = true; + ESP_LOGI(TAG,"Invalid fetched Heartbeat time value\r\n"); + } + + ESP_LOGI(TAG,"Heartbeat time in Sec : %d\r\n", config_heartbeat_time); + ESP_LOGI(TAG,"Heartbeat time in Hrs : %d\r\n", (config_heartbeat_time/HOURS_TO_SECONDS_COEFF)); + //___________________________ + + strret = strtok (NULL," "); + strcpy(epcheck, strret); + + if(!strcmp(epcheck,"EP\"") || !strcmp(epcheck,"EP")){ + ESP_LOGI(TAG,"(%s) %s message is terminated\r\n", epcheck,messageheader); + break; + } + else{ + ESP_LOGI(TAG,"(%s) %s message is not terminated!! \r\n", epcheck,messageheader); + } + + } + // TODO : Handle system time and print + /* + ESP_LOGI(TAG,"Year: %d\r\n",RTC_DateTime.Year); + ESP_LOGI(TAG,"Month: %d\r\n",RTC_DateTime.Month); + ESP_LOGI(TAG,"MonthDay: %d\r\n",RTC_DateTime.MonthDay); + ESP_LOGI(TAG,"Hour: %d\r\n",RTC_DateTime.Hour); + ESP_LOGI(TAG,"Minute: %d\r\n",RTC_DateTime.Minute); + ESP_LOGI(TAG,"WeekDay: %d\r\n",RTC_DateTime.WeekDay); + RTC_SetTimeDate(&RTC_DateTime); + */ + + // update relay state if changed + if(RelayState != PreviousRelayState) + { + ESP_LOGI(TAG,"Previous Relay State :%d \n",PreviousRelayState); + PreviousRelayState = RelayState; /* update PreviousRelayState */ + + if(RelayState == true) + { + /*============================*/ + port_vbatt_sense_enable(RELAY_ON); + ESP_LOGI(TAG,"Board relay state : %d\n",RelayState); + } + else + { + /*============================*/ + port_vbatt_sense_enable(RELAY_OFF); + ESP_LOGI(TAG,"Board relay state : %d\n ",RelayState); + } + } + else + { + ESP_LOGI(TAG,"Previous Relay State :%d \n",PreviousRelayState); + ESP_LOGI(TAG,"No changes in Relay State\r\n"); + /*Transition to idle state*/ + comms.poll_timer = true; //polling the comms_timer + //Comms_Check_TestMode(); + } + + int retval = COMMS_STATUS_OK; + //creating sp1 message + SP1_Mqtt_Tx(config_heartbeat_time); + + /* Run the MQTT publish sequence if nothing else pending */ + // retval = start_mqtt_publish_sequence(); + if(WIFI_STATUS_OK==retval) + { + ESP_LOGI(TAG,"MQTT Publish SP1 message success"); + + } + else + { + ESP_LOGI(TAG,"MQTT Publish SP1 message failed"); + + } + 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; +} + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*Handler for COMMS timer*/ static void timer_handler(void* context) { comms.poll_timer = true; } +<<<<<<< HEAD +======= +/* Parsing SP3 Message + The job of the COMM process is to fetch SP3 data from the server + and parse its fields. + + Following is a sample for SP3 message, in JSON format. + { + "IMEI": "862061049734352", + "SIMNumber": "862061049734352", + "McuUpdate": 1, + "ModemUpdate": 0, + "ConfigUpdate": 1 + } + We need to parse only McuUpdate, ModemUpdate and ConfigUpdate */ +static int Comms_Parse_SP3(char *buf, int len) +{ + char *strret; + char messageMAC[15]; + int retval; + // 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; + int ret = STATUS_ERROR; + if(buf != NULL) + strret = strstr(buf, "IMEI"); + else + return -1; + strncpy(messageMAC, &strret[7],(sizeof(messageMAC)/sizeof(messageMAC[0]))); + messageMAC[15] = '\0'; + + ret = mac_check_valid(messageMAC); + if(ret != false){ + //ok IMEI + ESP_LOGI(TAG,"Fetched IMEI matches board.\r\n"); + } + else{ + ESP_LOGW(TAG,"INVALID IMEI!!\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + return ret; + } + + strret = strstr(buf, "SIMNumber"); + + /***********/ + + data_parse_uint_value(&g_ID,"id", buf); + data_parse_uint_value(&g_SensorInt,"SensorInt", buf); + data_parse_uint_value(&g_ConfigUpdate,"ConfigUpdate", buf); + data_parse_uint_value(&g_McuUpdate,"McuUpdate", buf); + data_parse_uint_value(&g_ModemUpdate,"ModemUpdate", buf); + ESP_LOGI(TAG, "ConfigUpdate: %luMcuUpdate: %lu ModemUpdate: %lu", g_ConfigUpdate, g_McuUpdate, g_ModemUpdate); + + // teast ota enable + // g_McuUpdate = 1; + + if (g_McuUpdate == 1) { + McuUpdateFlag = true; + ESP_LOGI(TAG, "McuUpdateFlag: %d", McuUpdateFlag); + } else if (g_McuUpdate == '0') { + McuUpdateFlag = false; + ESP_LOGI(TAG, "McuUpdateFlag: %d", McuUpdateFlag); + } else + ESP_LOGE(TAG, "not valid value for McuUpdateFlag"); + + /***********/ + + // g_ConfigUpdate = 1; + ESP_LOGI(TAG, "g_ConfigUpdate: %lu",g_ConfigUpdate); + + if(g_ConfigUpdate == 1) + { + ConfigFlag = true; + ESP_LOGI(TAG,"\ConfigFlag: %d\n", ConfigFlag); + } + else if(g_ConfigUpdate == 0) + { + ConfigFlag = false; + ESP_LOGI(TAG,"\ConfigFlag: %d\n", ConfigFlag); + } + else + { + ESP_LOGE(TAG,"Not valid value for ConfigFlag"); + ConfigFlag = false; + } + + if(McuUpdateFlag == true){ + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP5\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP5); + } + else if(ConfigFlag == true){ + deviceCfged = true; + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP4\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP4); + } + else{ + ESP_LOGI(TAG,"Going to state COMMS_STATE_GOING_IDLE\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + return 0; +} + +//function to check if in test mode if not check : McuUpdateFlag ,ModemUpdateFlag. +//area for improvement +static void Comms_Check_TestMode(){ + + if(isTestMode == true){ + ESP_LOGI(TAG,"Going to COMMS_STATE_WAIT_HTTP_SEND_SP3\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP3); + } + else + if(McuUpdateFlag == true) + { + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP5\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP5); + } + else{ + if(ModemUpdateFlag == true) + { + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP6\r\n"); + comms.poll_timer = true; + /*36-update-comms.c uncommented the following line to enable the transition to sp6 */ + transition(COMMS_STATE_WAIT_HTTP_SEND_SP5); + } + else{ + ESP_LOGI(TAG,"Going to state COMMS_STATE_GOING_IDLE\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + } + + +} +static void Check_SP1_Order(){ + + if(WakeupFlag){ + WakeupFlag = false; + ESP_LOGI(TAG,"Going to COMMS_STATE_WAIT_HTTP_SEND_SP3\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP3); + } + else{ + if(isTestMode == true){ + ESP_LOGI(TAG,"Going to COMMS_STATE_WAIT_HTTP_SEND_SP3\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP3); + } + else{ + if(McuUpdateFlag == true) + { + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP5\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_WAIT_HTTP_SEND_SP5); + } + else + if(ModemUpdateFlag == true) + { + ESP_LOGI(TAG,"Going to state COMMS_STATE_WAIT_HTTP_SEND_SP6\r\n"); + comms.poll_timer = true; + /*36-update-comms.c uncommented the following line to enable the transition to sp6 */ + transition(COMMS_STATE_WAIT_HTTP_SEND_SP5); + } + else{ + ESP_LOGI(TAG,"Going to state COMMS_STATE_GOING_IDLE\r\n"); + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + } + + } + +} + +static void Wakeup_Send_SP1(void){ + + WakeupFlag = true; + int retval = COMMS_STATUS_OK; + //creating sp1 message + SP1_Mqtt_Tx(config_heartbeat_time); + + /* Run the MQTT publish sequence if nothing else pending */ + retval = start_mqtt_publish_sequence(); + + if(WIFI_STATUS_OK==retval) + { + ESP_LOGI(TAG,"MQTT Publish SP1 message success"); + + } + else + { + ESP_LOGI(TAG,"MQTT Publish SP1 message failed"); + + } + +} + + +static int wifi_check_net_connect(void) +{ + ESP_LOGI(TAG, "Attempting connection to google.com :)"); + + if(ESP_OK == http_client_test("https://www.google.com")) + { + ESP_LOGI(TAG, "Connection to internet successful."); + return WIFI_STATUS_OK; + } + else + { + + ESP_LOGI(TAG, "Connection to google.com failed.\n"); + return WIFI_STATUS_ERROR; + } +} + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static int state_machine(comms_event_t evt) { int retval = COMMS_STATUS_OK; @@ -1304,6 +2648,7 @@ static int state_machine(comms_event_t evt) { case COMMS_STATE_INIT: if (evt == COMMS_EVENT_START) +<<<<<<< HEAD { /* Set the number of check-in cycles to do and reset the checkin_cycle_counter */ number_of_check_in_to_do = nvm_get_last_written_history_sector() - nvm_get_last_posted_history_sector(); @@ -1590,11 +2935,98 @@ static int state_machine(comms_event_t evt) break; case COMMS_STATE_WAIT_HTTP_GET_CONFIG_FLAGS: +======= + { + /* Status is ERROR until cleared by successful completion. */ + comms.last_cycle_status = COMMS_STATUS_ERROR; + + if (wifi_isStarted()) + { + ESP_LOGI(TAG, "Wifi Started"); + wifi_event_cb(WIFI_STATUS_OK); + } + else + { + /* start the wifi process */ + retval = Connect_wifi_sta(WIFI_MODE_STA); + if (retval == WIFI_STATUS_OK) + { + comms.is_starting = true; + ESP_LOGI(TAG,"Wifi Connected....\n"); + transition(COMMS_STATE_WAIT_NET_CONNECT); + comms.poll_timer = true; + } + else + { + comms.is_starting = false; + ESP_LOGI(TAG,"Connecting to WiFi failed\n"); + transition(COMMS_STATE_GOING_IDLE); + comms.poll_timer = true; + } + } + } + break; + case COMMS_STATE_WAIT_WIFI: + break; + case COMMS_STATE_WAIT_NET_CONNECT: + ESP_LOGW(TAG,"Net connect .\n"); + + /* Wait for WiFi network connect event */ + if (evt == COMMS_EVENT_TIMER) + { + + retval = wifi_check_net_connect(); + if(retval == WIFI_STATUS_OK) + { + ESP_LOGI(TAG,"Network connected\r\n"); + + /* Sync time with NTP */ + obtain_time(); + client = esp_mqtt_client_init(&mqtt_cfg); /*Client init */ + esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); + + if (comms.connect_cb) { + comms.connect_cb(COMMS_STATUS_OK); + comms.connect_cb = 0; + } + comms.httpRetryCnt = HTTP_RETRY_COUNT; + ESP_LOGI(TAG,"Sending SP1 message\r\n"); + Wakeup_Send_SP1(); + } + else + { + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + + } + break; + + case COMMS_STATE_WAIT_HTTP_SEND_SP3: + ESP_LOGW(TAG,"COMMS_STATE_WAIT_HTTP_SEND_SP3.\n"); + + /* Wait for ESP-WiFi HTTP setup event */ + if (1) + // if (evt == COMMS_EVENT_TIMER) + { + /* Now make the GET request. */ + retval = start_http_get_request(COMMS_STATE_WAIT_HTTP_SEND_SP3, MCU_GET_CONFIG_FLAGS_URL1, "configuration", COMMS_STATE_WAIT_HTTP_GET_SP3); + // http_client_do_get_request(0, MAC_ID, response_buf); + + } + + break; + + case COMMS_STATE_WAIT_HTTP_GET_SP3: + + ESP_LOGI(TAG,"Start COMMS_STATE_WAIT_HTTP_GET_SP3"); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Wait for BG96 HTTP GET config event */ if (evt == COMMS_EVENT_TIMER) { /* Get the buffer and process the configuration. */ +<<<<<<< HEAD int len = 0; char* buf = 0; retval = modem_http_get_buf(&buf, &len); @@ -1616,12 +3048,27 @@ static int state_machine(comms_event_t evt) } else{ ESP_LOGI(TAG,"Modem get buff Failed (GET_CONFIG_FLAGS state)"); +======= + int len = 27; + char buf[512] = {0}; + // char *buf = 0; + retval = http_get_response_buf(buf, len); + if (retval == WIFI_STATUS_OK) + { + + ESP_LOGI(TAG,"BUF :\n%s\n",buf); + Comms_Parse_SP3(buf, len); + + } + else{ +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) comms.poll_timer= true; transition(COMMS_STATE_GOING_IDLE); } } break; +<<<<<<< HEAD case COMMS_STATE_WAIT_HTTP_POST_REQ: if(evt == COMMS_EVENT_TIMER) @@ -1679,6 +3126,60 @@ static int state_machine(comms_event_t evt) } break; +======= + + case COMMS_STATE_WAIT_HTTP_SEND_SP4: + + /* Wait for BG96 HTTP setup event */ + if (evt == COMMS_EVENT_TIMER) + { + /* Now make the GET request. */ + retval = start_http_get_request(COMMS_STATE_WAIT_HTTP_SEND_SP4, MCU_SP4_URL, "configuration", COMMS_STATE_WAIT_HTTP_GET_SP4); + } + + break; + + case COMMS_STATE_WAIT_HTTP_GET_SP4: + + ESP_LOGI(TAG, "COMMS_STATE_WAIT_HTTP_GET_SP4 start"); + + /* Wait for BG96 HTTP GET config event */ + // if (evt == COMMS_EVENT_TIMER) + if (1) + { + /* Get the buffer and process the configuration. */ + int len = 0; + char buf[512] ={0}; + retval = http_get_response_buf(buf, &len); + if (retval == WIFI_STATUS_OK) + { + + ESP_LOGI(TAG,"SP4 BUF :\n%s\n",buf); + + //SP4 parsing... + Comms_Parse_SP4(buf, len); + transition(COMMS_STATE_WAIT_MQTT_CONNECT); + comms.poll_timer = true; + } + else + { + comms.poll_timer = true; + transition(COMMS_STATE_GOING_IDLE); + } + } + break; + + case COMMS_STATE_WAIT_HTTP_SEND_SP5: + + /* Wait for BG96 HTTP setup event */ + if (evt == COMMS_EVENT_TIMER) + { + /* Now make the GET request. */ + retval = start_http_get_request(COMMS_STATE_WAIT_HTTP_SEND_SP5, MCU_SP5_URL, "McuUpdate", COMMS_STATE_WAIT_HTTP_GET_SP5); + } + break; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) case COMMS_STATE_WAIT_HTTP_GET_SP5: /* Wait for BG96 HTTP GET config event */ @@ -1686,6 +3187,7 @@ static int state_machine(comms_event_t evt) { /* Get the buffer and process the configuration. */ int len = 0; +<<<<<<< HEAD char* buf = 0; retval = modem_http_get_buf(&buf, &len); if (retval == MODEM_STATUS_OK) @@ -1693,17 +3195,30 @@ static int state_machine(comms_event_t evt) ESP_LOGI(TAG,"SP5 BUF: %s",buf); +======= + char buf[512] = {0}; + retval = http_get_response_buf(buf, &len); + if (retval == WIFI_STATUS_OK) + { + + ESP_LOGI(TAG,"SP5 BUF :\n%s\n",buf); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) //SP5 parsing... Comms_Parse_SP5(buf, len); } else { +<<<<<<< HEAD ESP_LOGI(TAG,"SP5 Parsing Failed"); +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) comms.poll_timer = true; transition(COMMS_STATE_GOING_IDLE); } } break; +<<<<<<< HEAD case COMMS_STATE_WAIT_HTTP_SEND_SP6: @@ -1828,17 +3343,77 @@ static int state_machine(comms_event_t evt) /* Set http_init_state to COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE */ comms.http_init_state = COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE; +======= + + case COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE: + + ESP_LOGI(TAG, "COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE start"); + + /* Set http_init_state to COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE */ + comms.http_init_state = COMMS_STATE_WAIT_HTTP_GET_MCU_UPDATE; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Wait for BG96 HTTP GET MCU update event */ //if (evt == COMMS_EVENT_TIMER) { comms.get_mcu_update = false; /* Get the buffer and process the MCU fw version message. */ +<<<<<<< HEAD //int len = 0; //char* buf = 0; //retval = modem_http_get_buf(&buf, &len); //if (retval == MODEM_STATUS_OK) { //if (COMMS_STATUS_OK == check_mcu_update(buf, len)) +======= + + /* Enable WIFI-OTA if MCU-FW is less than the one in SP5 message */ + + wifi_ota_start_firmware_update(MAC_ID); + while(OTA_IN_PROGRESS == wifi_ota_get_status()) + { + if (OTA_FATAL_ERROR == wifi_ota_get_status){ + + comms.poll_timer= true; + transition(COMMS_STATE_GOING_IDLE); + break; + } + vTaskDelay(100/portTICK_PERIOD_MS); + } + + if (OTA_FATAL_ERROR == wifi_ota_get_status){ + + comms.poll_timer= true; + transition(COMMS_STATE_GOING_IDLE); + break; + } + + /*if (retval == WIFI_STATUS_OK) + { + ESP_LOGI(TAG,"MCU FW download started\r\n"); + ///hmi_set_offload_mode(false); + transition(COMMS_STATE_WAIT_HTTP_GET_MCU_FILE); + //hmi_set_update_mode(true); + break; + } + else + { + ESP_LOGE(TAG,"MCU FW download failed to start\r\n"); + transition(COMMS_STATE_WAIT_MQTT_CONNECT); + comms.poll_timer = true; + Continue with session + }*/ + // hmi_set_leds_state(BLUE_LED_FLASHING_OTA); + // while(OTA_IN_PROGRESS == wifi_ota_get_status()) + // { + // vTaskDelay(100/portTICK_PERIOD_MS); + // } + + + if (retval == WIFI_STATUS_OK) + { + // if (COMMS_STATUS_OK == check_mcu_update(buf, len)) +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) { /* Different firmware on server. Use it. */ /* Setup URL: @@ -1847,6 +3422,7 @@ static int state_machine(comms_event_t evt) * to get the upper app) */ memset(comms.mqtt_buf, 0, sizeof(comms.mqtt_buf)); +<<<<<<< HEAD #if ST_OTA_HIGHER_APPLICATION //// snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), MCU_FW_BIN_FILE_URL1_LOWER, modem_get_imei()); @@ -1889,6 +3465,25 @@ static int state_machine(comms_event_t evt) int retval = modem_http_get_to_file(fwdl_op_cb, comms.mqtt_buf, MCU_OTA_FILE_LOCAL); if (retval == MODEM_STATUS_OK) +======= + +#if ST_OTA_HIGHER_APPLICATION +//// snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), MCU_PROG_URL_LOWER, bg96_get_imei()); +#elif ST_OTA_LOWER_APPLICATION +// snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), MCU_PROG_URL_HIGHER, bg96_get_imei()); +#else +//// snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), MCU_PROG_URL_LOWER, bg96_get_imei()); +#endif + /*Creating file path and store it in comms.mqtt_buf*/ + // char mac_str[15]; + // wifi_get_mac_addr(mac_str); + // snprintf(comms.mqtt_buf, sizeof(comms.mqtt_buf), MCU_PROG_URL, mac_str); + + /* Download the file data to modem file system */ + int retval = modem_http_get_to_file(fwdl_op_cb, comms.mqtt_buf, MCU_OTA_FILE_LOCAL); + + if (retval == WIFI_STATUS_OK) +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) { ESP_LOGI(TAG,"MCU FW download started\r\n"); ///hmi_set_offload_mode(false); @@ -1923,16 +3518,25 @@ static int state_machine(comms_event_t evt) ota_file_open_cb, /* Can fail and continue the comms state machine */ ota_file_data_cb); /* Callback for the file data in chunks */ +<<<<<<< HEAD if (retval == MODEM_STATUS_OK) { hmi_set_leds_state(BLUE_LED_FLASHING_OTA); +======= + if (retval == WIFI_STATUS_OK) + { +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) ESP_LOGI(TAG,"MCU FW update started\r\n"); transition(COMMS_STATE_WAIT_MCU_UPDATE); break; } else { +<<<<<<< HEAD ESP_LOGE(TAG,"MCU FW update failed to start\r\n"); +======= + ESP_LOGE(TAG, "MCU FW update failed to start\r\n"); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Continue with session */ //hmi_set_update_mode(false); } @@ -1951,20 +3555,142 @@ static int state_machine(comms_event_t evt) * OTA_terminate_connection sets the flag that is handled in OTA_Tick() * and main to do a reset to start the new application after comm completes. */ +<<<<<<< HEAD ESP_LOGD(TAG,"Ending OTA session, ready for reset\r\n"); ota_finish_processing(); +======= + ESP_LOGD(TAG, "Ending OTA session, ready for reset\r\n"); + +// OTA_terminate_connection(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Clear this, in case we have just turned on and have updated - * no need to trigger the startup callback in main. */ comms.is_starting = false; } +<<<<<<< HEAD +======= + // hmi_set_update_mode(false); + //hmi_set_offload_mode(true); + + } + break; + + case COMMS_STATE_WAIT_MQTT_CONNECT: + /* Wait for MQTT connection event */ + if (evt == COMMS_EVENT_TIMER) + { + /* When connected, we will publish everything we've got. + * First is the status message. + * Follow that with all messages in the BLE scan queue. + */ + ESP_LOGI(TAG,"MQTT connected\r\n"); + + /* Create the pub topic */ + memset(comms.mqtt_pub_topic, 0, MQTT_PUB_TOPIC_LEN); +#if COMMS_PUBLISH_WITH_IMEI + snprintf(comms.mqtt_pub_topic, MQTT_PUB_TOPIC_LEN, "unwired/%s", bg96_get_imei()); +#else + snprintf(comms.mqtt_pub_topic, MQTT_PUB_TOPIC_LEN, "unwiredct"); /* TF-58 */ +#endif + ESP_LOGD(TAG, "pub topic: [%s]\r\n", comms.mqtt_pub_topic); + + char mac_str[15]={0}; + + sprintf(comms.mqtt_pub_topic,"unwired/%s", mac_str); + /* Create the WF1 status message payload */ + //memset(comms.mqtt_buf, 0, sizeof(comms.mqtt_buf)); + //int len = create_type1_record(comms.mqtt_buf, sizeof(comms.mqtt_buf)); + //ESP_LOGD(TAG, "Payload: [%s]\r\n", comms.mqtt_buf); + ESP_LOGI(TAG,"SP1: [%s]\r\n", comms.mqtt_buf); + comms.wf1_msg = true; + + //board_led_all_off(); + //board_led_blue_on(); + hmi_choose_led(HMI_LED_BLUE, HMI_LED_BLINK); + + /* Publish the message */ + retval = -1; + retval = esp_mqtt_client_publish(client, MQTT_TOPIC_PUB, comms.mqtt_buf, 0, 0, 0); // Publish a message + if (retval == WIFI_STATUS_OK) + { + ESP_LOGI(TAG,"Publishing to MQTT broker\r\n"); + transition(COMMS_STATE_WAIT_MQTT_PUB); + comms.poll_timer = true; + } + } + break; + + case COMMS_STATE_WAIT_MQTT_PUB: + ESP_LOGI(TAG,"MQTT PUB event start \r\n"); + /* Wait for MQTT publish event */ + if (evt == COMMS_EVENT_TIMER) + { + if(!qmtopen_fail){ + ESP_LOGI(TAG,"Message published\r\n"); + /* Indicate success in publishing the messages */ + } + if (comms.wf1_msg) + { + /* waiting for 500ms for PUblish to complete.*/ +// Clock_Enable(); +// uint32_t start = Clock_Time(); +// uint32_t now; +// do { +// now = Clock_Time(); +// } while (now - start <= 100); +// Clock_Disable(); + } + //hmi_set_offload_success(); + + /* Also use this point to clear the ERROR status for use with retries. + * That is, if offload succeeded, we don't need to retry. + */ + comms.last_cycle_status = COMMS_STATUS_OK; + + retval = esp_mqtt_client_disconnect(client); + if (retval == WIFI_STATUS_OK) + { + ESP_LOGI(TAG,"Closing connection\r\n"); + transition(COMMS_STATE_WAIT_MQTT_CLOSE); + } + } + + break; + case COMMS_STATE_WAIT_MQTT_CLOSE: + + /* Wait for MQTT close event */ + if (evt == COMMS_EVENT_TIMER) + { + ESP_LOGI(TAG,"Connection closed.\r\n"); + + /*note: handler is disabled anyway*/ +// if(qmtopen_fail == true){ +// qmtopen_fail = false; +// //ESP_LOGI(TAG,"Message published\r\n"); +// ESP_LOGI(TAG,"Closing connection\r\n"); +// comms.poll_timer = true; +// transition(COMMS_STATE_WAIT_NET_CONNECT); +// } + + +// else{ + Check_SP1_Order(); + +// } + + + //Comms_Check_TestMode(); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } break; case COMMS_STATE_GOING_IDLE: +<<<<<<< HEAD /* Check if we can use WIFI as backup technique for check-in */ if((COMMS_OVER_CELL_WIFI_BACKUP == comms_mode) && (comms_do_wifi_backup)) { @@ -2109,6 +3835,108 @@ static int state_machine(comms_event_t evt) } break; +======= + /* Clear offloading data */ + //hmi_set_offload_mode(false); + + /* Clean up state before going idle */ + ESP_LOGI(TAG,"Process going idle.\n"); + + /*===========================================*/ +// retval = bg96_stop(); + /*===========================================*/ + transition(COMMS_STATE_IDLE); + comms.poll_timer = true; + + break; + case COMMS_STATE_IDLE: + if (evt == COMMS_EVENT_TIMER) + { + /* Status is ERROR until cleared by successful completion. */ + // comms.last_cycle_status = COMMS_STATUS_ERROR; + // + // ESP_LOGI(TAG,"Connecting to server. battery=%d\r\n", hmi_get_batt_level()); + // if (bg96_is_ready()) + // { + // /* If modem is started and ready, proceed. */ + // wifi_event_cb(WIFI_STATUS_OK); + // } + // else if (!bg96_is_started()) + // { + // /* start the bg96 process only if not started. */ + // retval = bg96_start(wifi_event_cb); + // if (retval == WIFI_STATUS_OK) + // { + // ESP_LOGI(TAG,"Waiting for modem\r\n"); + // transition(COMMS_STATE_WAIT_BG96); + // } + // } + // else + // { + // ESP_LOGW(TAG,("Modem is busy. Comm cycle aborted.\r\n"); + // } + + + /*===========================================*/ + /* turn modem off*/ + int retval=0; +// retval = bg96_stop(); + if(!retval ){ + comms.poll_timer = true; + hmi_choose_led(HMI_LED_RED, HMI_LED_ON); + // transition(COMMS_STATE_WAIT_BG96_OFF); + }else + { + ESP_LOGI(TAG,"bg96 faild stop \r\n"); + } + + + /*===========================================*/ + + + // board_led_red_on(); + // board_relay_off(); + // ESP_LOGI(TAG,"going to http setup\n"); + /*===========================================*/ + // comms.poll_timer = true; + // transition(COMMS_STATE_WAIT_RELAY_WAIT); + // transition(COMMS_STATE_WAIT_HTTP_SEND_SP3); + + // } + // if (evt == COMMS_EVENT_TIMER) + // { + // + // } + // else if (evt == COMMS_EVENT_STOP) + // { + // ESP_LOGI(TAG,"Process stopped.\n"); + // transition(COMMS_STATE_INIT); + } + break; + +// case COMMS_STATE_RELAY_WAIT: +// if (evt == COMMS_EVENT_TIMER) +// { +// board_led_red_off(); +// board_relay_on(); +// ESP_LOGI(TAG,"RELAY OFF\n"); +// timer_stop(COMMS_TIMER_ID); +// transition(COMMS_STATE_GOING_IDLE); +// /*=========*/ +// comms.poll_timer = true; +// +// } +// break; + + case COMMS_STATE_WAIT: + +// timer_stop(COMMS_TIMER_ID); + comms.poll_timer = true; + transition(comms.http_init_state); + ESP_LOGI(TAG,"Number of remaining HTTP retry is : %d\n", comms.httpRetryCnt); + break; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) default: break; } @@ -2118,6 +3946,7 @@ static int state_machine(comms_event_t evt) /* ------------------------------------------------------------------------- */ +<<<<<<< HEAD char* get_mac(void){ @@ -2154,6 +3983,8 @@ char* get_mac(void){ } +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Initialize. */ int comms_init(void) { @@ -2163,6 +3994,7 @@ int comms_init(void) comms.overflow_check = 0xFF; /*Initializing the COMMS_TIMER */ +<<<<<<< HEAD const esp_timer_create_args_t comms_timer_args = { .callback = &timer_handler, /* argument specified here will be passed to timer callback function */ @@ -2174,6 +4006,12 @@ int comms_init(void) comms.poll_timer = false; ESP_LOGI(TAG,"Process initialized.\n"); +======= +// timer_init(COMMS_TIMER_ID, timer_handler); + + ESP_LOGI(TAG,"Process initialized.\n"); +// register_wifi_callback(wifi_event_cb); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) return retval; } @@ -2181,6 +4019,10 @@ int comms_init(void) /* Start the process */ int comms_start(comms_op_cb_t start_cb, comms_op_cb_t connect_cb) { +<<<<<<< HEAD +======= + ESP_LOGW(TAG, "Comms start ...."); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) comms.start_cb = start_cb; comms.connect_cb = connect_cb; int retval = state_machine(COMMS_EVENT_START); @@ -2243,6 +4085,10 @@ int comms_get_status(void) /* ------ Process Callbacks ------------------------- */ +<<<<<<< HEAD __attribute__((weak)) void comms_ready_cb(void) { } +======= +__attribute__((weak)) void comms_ready_cb(void) { } +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/main/comms.h b/main/comms.h index 4bcd1d1..2af4a50 100644 --- a/main/comms.h +++ b/main/comms.h @@ -1,3 +1,4 @@ +<<<<<<< HEAD /* * comms.h * @@ -17,6 +18,18 @@ * * Copyright 2020 HAE Innovations * +======= +#ifndef __COMMS_H_ +#define __COMMS_H_ + +#include +#include + +/* comms.h + * + * Copyright 2020 HAE Innovations + * +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) * Celluar Communications process manager. * * Handles communication to/from server over cell modem, @@ -48,6 +61,7 @@ #define PARTHA_SERVER_BASE_URL "https://www.parthasarathimishra.com" +<<<<<<< HEAD #define TESTING_SERVER_BASE_URL "http://54.204.230.201:8085" @@ -68,6 +82,9 @@ typedef enum #if (TEMPSTICK_SERVER == 1) +======= +#define TESTING_SERVER_BASE_URL "http://54.204.230.201:8081" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*HTTP POST header component for tempstick server*/ #define END_POINT_POSTING1 "POST / HTTP/1.1\r\n" @@ -90,9 +107,15 @@ typedef enum #define MCU_POST_URL3 MCU_BASE_URL3 //URL to get configuration flags from servers 1, 2, and 3 +<<<<<<< HEAD #define MCU_GET_CONFIG_FLAGS_URL1 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/"//MCU_BASE_URL1//config/flag/server1 #define MCU_GET_CONFIG_FLAGS_URL2 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/"//MCU_BASE_URL2//config/flag/server2 #define MCU_GET_CONFIG_FLAGS_URL3 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/"//MCU_BASE_URL3//config/flag/server3 +======= +#define MCU_GET_CONFIG_FLAGS_URL1 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/" //MCU_BASE_URL1//config/flag/server1 +#define MCU_GET_CONFIG_FLAGS_URL2 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/" //MCU_BASE_URL2//config/flag/server2 +#define MCU_GET_CONFIG_FLAGS_URL3 TESTING_SERVER_BASE_URL"/hae/azuma/%s/update/" //MCU_BASE_URL3//config/flag/server3 +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* this endpoint not implemented yet in the code (customer pending) */ // if the config_update flag is set @@ -122,6 +145,7 @@ typedef enum #define MODEM_FW_BIN_FILE_URL3 TESTING_SERVER_BASE_URL"/hae/azuma/%s/modem_pgm_download/MOTA.bin"//MCU_BASE_URL3//modem/fw/bin/file/server3 +<<<<<<< HEAD #else @@ -236,6 +260,8 @@ typedef enum +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* TEMPSTICK servers URL's */ typedef enum { TEMPSTICK_SERVER1=1, @@ -243,6 +269,14 @@ typedef enum { TEMPSTICK_SERVER3 }serverUrl_t; +<<<<<<< HEAD +======= + +#define COMMS_STATUS_UPDATED 1 +#define COMMS_STATUS_OK 0 +#define COMMS_STATUS_ERROR -1 + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* Operation complete indication callback */ typedef void (*comms_op_cb_t)(int status); @@ -264,7 +298,11 @@ int comms_poll(void); /* Check if the process needs to be polled. */ bool comms_needs_poll(void); +<<<<<<< HEAD /* Connect to server once process has completed startup and is idle +======= +/* Connect to server once process has completed startup and is idle +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) * Optional callback is invoked when process completes. */ int comms_connect(comms_op_cb_t cb); @@ -281,7 +319,16 @@ bool comms_is_started(void); */ int comms_get_status(void); +<<<<<<< HEAD // Get MAC id char* get_mac(void); #endif /* MAIN_COMMS_H_ */ +======= + +void SP1_Mqtt_Tx(int ); + + +#endif /* __COMMS_H_ */ + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/main/data_processing.c b/main/data_processing.c index be495b4..f4c1955 100644 --- a/main/data_processing.c +++ b/main/data_processing.c @@ -24,10 +24,14 @@ #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" @@ -44,7 +48,10 @@ static const char* TAG = "DATA"; 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; @@ -73,6 +80,7 @@ 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; @@ -182,6 +190,9 @@ static bool isThermocouplePresent = false; 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 @@ -214,6 +225,7 @@ typedef struct RTC_DATA_ATTR rtcRamData_t _rtcRamData; +<<<<<<< HEAD uint32_t data_get_send_interval(void) { if(esp_settings->sendInterval) @@ -227,6 +239,8 @@ 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; @@ -456,6 +470,7 @@ static esp_err_t data_parse_String_value(char *target_buffer, const char needle[ } +<<<<<<< HEAD static void setAccelerometerPowerState(void) { @@ -2392,6 +2407,8 @@ void data_initialize_rtc_ram(void) _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++) @@ -2471,7 +2488,10 @@ void data_clearWifiConnectionSettings(void) +<<<<<<< HEAD +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*******************************************************************/ /* Buffer(Json Sample) */ /*{ "request": "settings", "time":1675859084, "id":10608508, @@ -2481,13 +2501,20 @@ void data_clearWifiConnectionSettings(void) 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); @@ -2495,6 +2522,7 @@ esp_err_t data_parsing_config(char *buff,int len){ 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) @@ -2504,6 +2532,25 @@ esp_err_t data_parsing_config(char *buff,int len){ { 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; } @@ -2526,6 +2573,7 @@ esp_err_t check_in_attempts_count( int httpRetryCnt, int maxretrynum ) } +<<<<<<< HEAD /* should use in main.c to initiate sendDetails var*/ void init_send_Details(void) { @@ -2608,4 +2656,6 @@ void data_set_urlConnect(void) +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/main/hmi.c b/main/hmi.c index 24174dc..eff3220 100644 --- a/main/hmi.c +++ b/main/hmi.c @@ -22,7 +22,10 @@ #include "comms.h" #include "port.h" #include "adc_ifx.h" +<<<<<<< HEAD #include "i2c_sensors.h" +======= +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include "data_processing.h" #include "hmi.h" @@ -44,6 +47,14 @@ static const char* TAG = "HMI"; #define BLUE_RED_FLASHING_200ms_DURARION 200 // Duration for BLUE_RED_FLASHING led_event #define NORMAL_HMI_DURATION 1000 // Duration for NORMAL_HMI cycle (cycle without triggered events) +<<<<<<< HEAD +======= +/*LED definitions*/ +#define RED_TRI_LED 0 +#define GREEN_TRI_LED 1 +#define BLUE_TRI_LED 2 + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static QueueHandle_t hmi_queue; // FIFO queue that stores the leds event @@ -555,6 +566,11 @@ void hmi_stop_ota_event(void) } bool leds_enabled = true; +<<<<<<< HEAD +======= + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void set_leds_enable(bool status) { leds_enabled = status; @@ -564,6 +580,68 @@ void set_leds_enable(bool status) port_blue_led_off(); } } +<<<<<<< HEAD +======= +/* State of the hmi process */ +typedef enum +{ + HMI_STATE_INIT, + HMI_STATE_RUN, +} hmi_state_t; + +typedef struct +{ + hmi_state_t state; + /* Timer */ + bool poll_timer; + /* General 1 sec timer */ + int sec_timer; + int active_led; + bool red_led_on; + bool green_led_on; + bool blue_led_on; + uint8_t led_state; + int** blink_pattern; +} hmi_t; + +static hmi_t hmi; + +int hmi_choose_led(int led_color,uint8_t op_mode) +{ + // int retval=HMI_STATUS_OK; + hmi.led_state = op_mode; /*led state ( on,off or blinking).*/ + + switch (led_color) + { + + case RED_TRI_LED: + hmi.red_led_on = 1; + hmi.green_led_on = 0; + hmi.blue_led_on = 0; + break; + + case GREEN_TRI_LED: + hmi.red_led_on = 0; + hmi.green_led_on = 1; + hmi.blue_led_on = 0; + + break; + case BLUE_TRI_LED: + hmi.red_led_on = 0; + hmi.green_led_on = 0; + hmi.blue_led_on = 1; + + break; + default: + hmi.red_led_on = 0; + hmi.green_led_on = 0; + hmi.blue_led_on = 0; + break; + } + return 0; +} + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* This is the hmi_task that will be executed periodically*/ void hmi_task(void *pvParameters) diff --git a/main/hmi.h b/main/hmi.h index 75c28fb..c692c15 100644 --- a/main/hmi.h +++ b/main/hmi.h @@ -8,6 +8,12 @@ #ifndef MAIN_HMI_H_ #define MAIN_HMI_H_ +<<<<<<< HEAD +======= +#include +#include +#include +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) typedef enum{ BLUE_LED_FLASHING, // Connecting to LTE Network BLUE_LED_FLASHING_OTA, // OTA Update Firmware @@ -21,6 +27,26 @@ typedef enum{ BLUE_RED_LEDS_OFF }hmi_leds_state_t; +<<<<<<< HEAD +======= +typedef enum +{ + HMI_LED_RED, + HMI_LED_GREEN, + HMI_LED_BLUE, + + HMI_LED__MAX__ +} hmi_led_type_t; + +typedef enum +{ + HMI_LED_OFF = 0, + HMI_LED_ON, + HMI_LED_BLINK, + +} hmi_led_state_t; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void hmi_init(void); void hmi_set_leds_state(hmi_leds_state_t status); void hmi_stop_continued_led_state(hmi_leds_state_t led_event); @@ -31,5 +57,9 @@ void hmi_task(void *pvParameters); void set_leds_enable(bool status); void hmi_do_usb_event_inside_hmi(bool decision); void hmi_exception_usb_event(void); +<<<<<<< HEAD +======= +int hmi_choose_led(int led_color,uint8_t op_mode); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #endif /* MAIN_HMI_H_ */ diff --git a/main/main.c b/main/main.c index 950a2cb..3f28392 100644 --- a/main/main.c +++ b/main/main.c @@ -1,4 +1,8 @@ +<<<<<<< HEAD +======= +#include +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include #include #include @@ -22,7 +26,11 @@ #include "lwip/sockets.h" #include "lwip/dns.h" +<<<<<<< HEAD #include "lwip/netdb.h"- +======= +#include "lwip/netdb.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include "freertos/FreeRTOS.h" @@ -33,10 +41,46 @@ #include "esp_timer.h" #include #include "rtc.h" +<<<<<<< HEAD #include "data_processing.h" #include "wifi_Client.h" +======= +#include "wifi_Client.h" +#include "data_processing.h" +#include "driver/gpio.h" +#include "comms.h" +#include "driver/timer.h" + +#include "port.h" + +#define HEARTBEAT_TIME_SEC_TEST 2 +#define HEARTBEAT_TIME_SEC 2 //14400 + +/* Unique timer ID for checking the value of isTestMode variable (should not be true for more than 1hr) */ +#define COMMS_TESTMODE_ID 3 +#define TESTMODE_DURATION 3600000 + +//#define RESTART_THRESHOLD 10 // Threshold in seconds + +//communication init flag +extern bool deviceCfged; +extern int config_heartbeat_time; +bool isCommInit = false; +bool isTestMode = false; +bool isFirstRun = true; +bool isTestModeTimerOff = true; + +int heartbeat_time = HEARTBEAT_TIME_SEC; +bool testmode_timeout = false; +static bool heartbeat_event_flag = false; + +// Global variable to store the initialization timestamp +uint32_t init_timestamp = 0; +// Global variable to store the last check timestamp +uint32_t last_check_timestamp = 0; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) @@ -46,9 +90,14 @@ #define MQTT_TOPIC_SUB "/topic/qos0" #define MQTT_TOPIC_PUB "/topic/qos0" +<<<<<<< HEAD #define WEB_SERVER "54.204.230.201" #define WEB_PORT "8085" +======= +#define WEB_SERVER "54.204.230.201" +#define WEB_PORT "8081" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define WEB_PATH "/hae/azuma/353165803930522/update/" #define MCU_CONFIG "/hae/azuma/353165803930522/mcu_config_download/" #define MCU_PROG_VER "/hae/azuma/353165803930522/mcu_pgm_download/version/" @@ -56,18 +105,166 @@ #define BROCKER_URL_TEST "mqtt://broker.mqtt.cool:1883" +<<<<<<< HEAD #define SP3_URL "http://54.204.230.201:8085/hae/azuma/353165803930522/update/" //#define BROCKER_URL_TEST "mqtt://azumamqtt1.cedalo.cloud:1883" +======= +// #define BROCKER_URL_TEST "mqtt://azumamqtt1.cedalo.cloud:1883" + +char MAC_ID[16] ="353165803930522\0"; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) uint8_t comms_mode = DEFAULT_COMMS_MODE; char HTTP_GET_DATA[512]; +<<<<<<< HEAD const char *TAG = "main"; char* SP1_data(void) { static char sp1[] = "SP1 F/W TIME_DATA"; return sp1; +======= + +bool RelayState_1 = false; +bool PreviousRelayState_1 = false; + +#define RELAY_PIN 42 // Define GPIO14 +#define RELAY_ON 1 +#define RELAY_OFF 0 +#define HOURS_TO_SECONDS_COEFF 3600 + + +#define TIMER_DIVIDER 16 // Prescaler (80MHz / 16 = 5MHz) +#define TIMER_SCALE (APB_CLK_FREQ / TIMER_DIVIDER) // 5,000,000 ticks per second +#define TIMER_INTERVAL_SEC 5 // 1-minute interval +bool timer_on = false; + +const char *TAG = "main"; + +/* This timer triggers server connections based on a fundamental + * timer (e.g. heartbeat timer). It never resets. + */ +static uint32_t comms_timer = 0; +uint32_t extern_comms_timer = 0; +/* flag associated with comm process intervals signaling that a + * connection should be made. + */ +bool initialize_completed_event_flag = false; + +/*Relay-Controlling*/ +void board_relay_on(void) +{ + gpio_set_level(RELAY_PIN, RELAY_ON); // Set GPIO14 HIGH + ESP_LOGI(TAG,"Relay ON"); +} + +void board_relay_off(void) +{ + gpio_set_level(RELAY_PIN, RELAY_OFF); // Set GPIO14 LOW + ESP_LOGI(TAG,"Relay OFF"); +} + +static void comms_started_cb(int status) +{ + /* Comms process has started and configuration has been updated. */ + initialize_completed_event_flag = true; +} +static void comms_connect_cb(int status) +{ + isCommInit = true; +} + +bool main_hearbeat = 0; + +int app_tick() +{ + static int retval; + + /* This heartbeat is for timing communication cycles and other main system functions. */ + if (heartbeat_event_flag) + { + heartbeat_event_flag = false; + + comms_timer++; + extern_comms_timer++; + + ESP_LOGI(TAG, "Comms timer value = %d",(uint8_t)comms_timer); + + if(comms_timer >= heartbeat_time) //2 mins + { + comms_timer = 0; + extern_comms_timer = 0; + main_hearbeat = 1; + } + + if(main_hearbeat) + { + main_hearbeat = 0; + + if(isCommInit == true) + { + isCommInit = false ; + isFirstRun = false; + + comms_start(comms_started_cb, comms_connect_cb); + } + } + + if(isTestMode) + { + heartbeat_time = HEARTBEAT_TIME_SEC_TEST; + + if(isTestModeTimerOff) + { + isTestModeTimerOff = false; + /*Start COMMS_TESTMODE_TIMER to prevent the "TESTMODE" to last more than 1hr*/ +// timer_start(COMMS_TESTMODE_ID,TESTMODE_DURATION); + } + + } + else + { + //Seraj + // if(isFirstRun == false){ + if(deviceCfged == true) { + //don't set hbt as default value + heartbeat_time = config_heartbeat_time; + //heartbeat_time = 180; + } + else{ + heartbeat_time = HEARTBEAT_TIME_SEC; + //heartbeat_time = 180; + } + // } + } + + /* Heartbeat event is driven by watchdog. Servicing is automatic */ +// watchdog_service(); + + /* comms process */ + if (comms_needs_poll()) + { + int retval = comms_poll(); + if (retval != 0) + { + ESP_LOGE(TAG, "comms poll error: %d\r\n", retval); + } + } + } + return retval; +} + +int sum_digits(int digit) +{ + int sum = 0; + while (digit > 0) + { + sum = sum + digit % 10; + digit = digit / 10; + } + return sum; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } void get_mac_add(void) { // The function modifies the passed buffer @@ -93,6 +290,7 @@ void get_mac_add(void) { // The function modifies the passed buffer printf("Formatted MAC (15 Characters): %s\n", MAC_ID); } +<<<<<<< HEAD typedef enum { MQTT_STATE_INIT, MQTT_STATE_CONNECT, @@ -283,6 +481,328 @@ void http_get_request(const char *path) { close(sock); freeaddrinfo(res); +======= + +static bool mac_check_valid(char *message_mac) +{ + //find the length of message imei + int len = strlen(message_mac); + int sum = 0; + ESP_LOGI(TAG,"MESSAGE MAC_ID : %s\r\n",message_mac); + ESP_LOGI(TAG,"BOARD MAC_ID : %s\r\n",MAC_ID); + + ESP_LOGI(TAG,"SIZE OF MAC ID : %d\r\n",len); + + //check length of imei field + if (len != 15){ + //invalid IMEI + ESP_LOGW(TAG,"Invalid MAC length"); + return false; + } + if(!strcmp(message_mac,MAC_ID)){ + + for(int i = len-1 ; i >= 0; i--) + { + //check if message imei fields contain numbers (0-9) + if((message_mac[i] > 47) && (message_mac[i] < 58)){ + int digit = (message_mac[i] - 48); + // Doubling every alternate beginning at [13] digit + //ignore last number [14] and first number [0] as well + if (i % 2 != 0) + digit = 2 * digit; + // Finding sum of the digits + // if digit*2 is a two digit number add the two digits + sum += sum_digits(digit); + + } + else{ + ESP_LOGW(TAG,"Invalid MAC (not numerical values)\r\n"); + return false; + } + } + } + else{ + ESP_LOGI(TAG,"Message MAC doesn't match board MAC ID\r\n"); + return false; + } + + return (sum % 10 == 0); +} + +static int Comms_Parse_SP4(char *buf, int len){ + + char messageheader[4] = {0}; + char date_time[18] = {'0'}; + char messageIMEI[15] = {'0'}; + char testMode[3] = {'0'}; + int sp4_ret = -1; + char* strret = NULL; + char hbeat[5] = {'0'}; + char epcheck[2] = {0}; + + strret = strtok(buf," "); + strcpy(messageheader, strret); + ESP_LOGI(TAG,"%s message is received \r\n",messageheader); + while(strret != NULL){ + + + strret = strtok (NULL," "); + strcpy(messageIMEI, strret); + //messageIMEI[15] = '\0'; + + sp4_ret = mac_check_valid(messageIMEI); + if(sp4_ret != false){ + //ok IMEI + ESP_LOGI(TAG,"Fetched IMEI matches board.\r\n"); + } + else{ + ESP_LOGI(TAG,"INVALID IMEI!!\r\n"); + // comms.poll_timer = true; + // transition(COMMS_STATE_GOING_IDLE); + return sp4_ret; + } + + /*Parse string for date/time*/ + strret = strtok (NULL," "); + strcpy(date_time, strret); + + + + ESP_LOGI(TAG,"Date Time : %s\r\n",date_time); + + strret = strtok (NULL," "); + if(strret[0] == '1'){ + RelayState_1 = true; + }else + { + RelayState_1 = false; + } + + ESP_LOGI(TAG,"Relay State : %d\r\n",RelayState_1); +// //heartbeat_time = (buf[43] - 48) * HOURS_TO_SECONDS_COEFF ; +// heartbeat_time = (buf[44] - 48) * HOURS_TO_SECONDS_COEFF ; +// +// LOG_INFO("Heartbeat time in hrs : %d\r\n", (heartbeat_time/HOURS_TO_SECONDS_COEFF)); + + strret = strtok (NULL," "); + strcpy(hbeat, strret+2); + + ESP_LOGI(TAG,"fetched Heartbeat time value %s \r\n", hbeat); + ESP_LOGI(TAG,"previous Heartbeat time value %d \r\n", config_heartbeat_time); + + + /*moved changing heartbeat so that it comes after looking for test mode field and configuring it*/ + config_heartbeat_time = atoi(hbeat); + strret = strtok(NULL," "); + strcpy(testMode, strret); + if(testMode[2] == '1') + { + if(testmode_timeout){ + isTestMode = false; + testmode_timeout = false; + } + else{ + isTestMode = true; + } + + } + else + { + isTestMode = false; + } + //===================================== + ESP_LOGI(TAG,"Test Mode: %d\r\n",isTestMode); + + //maximum heartbeat time is 4 days (96 hours) + if((config_heartbeat_time != 0) && (config_heartbeat_time < 97 && config_heartbeat_time > 0)){ + ESP_LOGI(TAG,"Valid fetched Heartbeat time value\r\n"); + config_heartbeat_time *= HOURS_TO_SECONDS_COEFF; + deviceCfged = true; + } + else{ + config_heartbeat_time = HEARTBEAT_TIME_SEC; + deviceCfged = true; + ESP_LOGI(TAG,"Invalid fetched Heartbeat time value\r\n"); + } + + ESP_LOGI(TAG,"Heartbeat time in Sec : %d\r\n", config_heartbeat_time); + ESP_LOGI(TAG,"Heartbeat time in Hrs : %d\r\n", (config_heartbeat_time/HOURS_TO_SECONDS_COEFF)); + //___________________________ + + strret = strtok (NULL," "); + strcpy(epcheck, strret); + + if(!strcmp(epcheck,"EP\"") || !strcmp(epcheck,"EP")){ + ESP_LOGI(TAG,"(%s) %s message is terminated\r\n", epcheck,messageheader); + break; + } + else{ + ESP_LOGI(TAG,"(%s) %s message is not terminated!! \r\n", epcheck,messageheader); + } + + } + /* ============================ + temp[0] = date_time[0]; + temp[1] = date_time[1]; + temp[2] = date_time[2]; + temp[3] = date_time[3]; + + RTC_DateTime.Year = atoi(temp); + + ==============TEST============== + LOG_INFO("Year: %d\r\n",RTC_DateTime.Year); + ============================ + + temp[0] = date_time[5]; + temp[1] = date_time[6]; + temp[2] = ' '; + temp[3] = ' '; + RTC_DateTime.Month = atoi(temp); //mm value to integer + + ==============TEST============== + LOG_INFO("Month: %d\r\n",RTC_DateTime.Month); + ============================ + + temp[0] = date_time[8]; + temp[1] = date_time[9]; + temp[2] = ' '; + temp[3] =' '; + RTC_DateTime.MonthDay = atoi(temp); //dd value to integer + + ==============TEST============== + LOG_INFO("MonthDay: %d\r\n",RTC_DateTime.MonthDay); + ============================ + temp[0] = date_time[11]; + temp[1] = date_time[12]; + temp[2] = ' '; + temp[3] =' '; + RTC_DateTime.Hour = atoi(temp); //HH value to integer + + ==============TEST============== + LOG_INFO("Hour: %d\r\n",RTC_DateTime.Hour); + ============================ + temp[0] = date_time[14]; + temp[1] = date_time[15]; + temp[2] = ' '; + temp[3] = ' '; + RTC_DateTime.Minute = atoi(temp); //hh value t integer + + ==============TEST============== + LOG_INFO("Minute: %d\r\n",RTC_DateTime.Minute); + ============================ + temp[0] = date_time[17]; + temp[1] = ' '; + temp[2] = ' '; + temp[3] = ' '; + RTC_DateTime.WeekDay = atoi(temp); + + ==============TEST============== + LOG_INFO("WeekDay: %d\r\n",RTC_DateTime.WeekDay); + ============================ + //rtc_set_timestamp(&rtcData); + RTC_SetTimeDate(&RTC_DateTime);*/ + + // update relay state if changed + if(RelayState_1 != PreviousRelayState_1) + { + + + ESP_LOGI(TAG,"Previous Relay State :%d \n",PreviousRelayState_1); + PreviousRelayState_1 = RelayState_1; /* update PreviousRelayState */ + + if(RelayState_1 == true) + { + /*============================*/ + board_relay_on(); + //board_led_all_off(); + //board_led_green_on(); + //hmi_choose_led(HMI_LED_GREEN, HMI_LED_ON); + + ESP_LOGI(TAG,"Board relay state : %d\n",RelayState_1); + } + else + { + /*============================*/ + board_relay_off(); + //board_led_all_off(); + //board_led_red_on(); + // hmi_choose_led(HMI_LED_RED, HMI_LED_ON); + + ESP_LOGI(TAG,"Board relay state : %d\n ",RelayState_1); + } + + } + else + { + ESP_LOGI(TAG,"Previous Relay State :%d \n",PreviousRelayState_1); + ESP_LOGI(TAG,"No changes in Relay State\r\n"); + /*Transition to idle state*/ + //comms.poll_timer = true; //polling the comms_timer + //Comms_Check_TestMode(); + } + + + int retval = COMMS_STATUS_OK; + //creating sp1 message + SP1_Mqtt_Tx(config_heartbeat_time); + + /* Run the MQTT publish sequence if nothing else pending */ + // retval = start_mqtt_publish_sequence(); + if(retval == 1) + { + ESP_LOGI(TAG,"MQTT Publish SP1 message success"); + + } + else + { + ESP_LOGI(TAG,"MQTT Publish SP1 message failed"); + + } + return 0; +} + +// Interrupt Service Routine (ISR) +void IRAM_ATTR timer_isr_callback(void *param) { + int timer_idx = (int)param; + + // Clear the interrupt flag + timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, timer_idx); + + // Re-enable the timer alarm + timer_group_enable_alarm_in_isr(TIMER_GROUP_0, timer_idx); + + heartbeat_event_flag = true; +} + +// Timer Initialization +void my_timer_init() { + // Disable existing interrupts before registering a new one + timer_deinit(TIMER_GROUP_0, TIMER_0); + + timer_config_t config = { + .divider = TIMER_DIVIDER, + .counter_dir = TIMER_COUNT_UP, + .alarm_en = TIMER_ALARM_EN, + .auto_reload = true, // Restart timer after reaching the alarm value + .intr_type = TIMER_INTR_LEVEL + }; + + timer_init(TIMER_GROUP_0, TIMER_0, &config); + timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0); + timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_SCALE * TIMER_INTERVAL_SEC); + timer_enable_intr(TIMER_GROUP_0, TIMER_0); + + // Register the ISR with SHARED interrupt flag + esp_err_t err = timer_isr_callback_add(TIMER_GROUP_0, TIMER_0, timer_isr_callback, (void*)TIMER_0, ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_IRAM); + + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to register timer ISR: %s", esp_err_to_name(err)); + return; + } + + // Start the timer + timer_start(TIMER_GROUP_0, TIMER_0); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } void app_main(void) @@ -297,6 +817,7 @@ void app_main(void) /* Create the UART tasks for both UART0 and UART1 */ uart_create_rx_tasks(); +<<<<<<< HEAD // Get firmwae version @@ -464,6 +985,89 @@ void app_main(void) // OTA start wifi_ota_start_firmware_update(IMEI); +======= +/* + while(1) { + + port_red_led_on(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + port_red_led_off(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + port_blue_led_on(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + port_blue_led_off(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + port_green_led_on(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + port_green_led_off(); + + // app_tick(); + ESP_LOGI(TAG, "LED testing running ...."); + }*/ + + + // get_mac(mac_address); + // printf("MAC Address in main: %s\n", mac_address); + + /*while(1){ + + + port_vbatt_sense_enable(0); + ESP_LOGI(TAG, "Realy ON"); + vTaskDelay(1500/portTICK_PERIOD_MS); + + port_accel_pwr_enable(1); + ESP_LOGI(TAG, "Realy OFF"); + vTaskDelay(1500/portTICK_PERIOD_MS); + + }*/ + + + /* Start On-Boarding process */ + webserver_start(); + + get_mac_add(); + + /* Wait till the onboarding process is completed */ + while(!webserver_get_status()) + { + vTaskDelay(750/portTICK_PERIOD_MS); + ESP_LOGI(TAG, "Waiting from wifi connect ....."); + port_blue_led_toggle(); + } + port_red_led_off(); + port_green_led_on(); + wifi_first_init(); + +// Connect_wifi_sta(WIFI_MODE_STA); + + uint8_t ret = comms_init(); + if ( ret == COMMS_STATUS_OK ) + { + ESP_LOGI(TAG, "Comms init Successfully :) "); + comms_start(comms_started_cb, comms_connect_cb); + } else + { + ESP_LOGW(TAG, "Comms init faild :("); + } + + my_timer_init(); + +// char url_sp4[]="http://54.204.230.201:8081/hae/azuma/128101153943920/mcu_config_download/"; +// char res[512]; +// http_client_get(url_sp4, res); +// ESP_LOGI(TAG, "SP4 ===> messgage \n %s",res); +// +// Comms_Parse_SP4(res, sizeof(res)); + + while(1) { + + vTaskDelay(1000 / portTICK_PERIOD_MS); + app_tick(); + ESP_LOGI(TAG, "App tick running ...."); + } + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } diff --git a/main/main.h b/main/main.h index b2ccfc6..1d4dd98 100644 --- a/main/main.h +++ b/main/main.h @@ -8,7 +8,12 @@ #ifndef MAIN_MAIN_H_ #define MAIN_MAIN_H_ +<<<<<<< HEAD extern char MAC_ID[15]; +======= +#include +extern char MAC_ID[16]; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define SENS_INT_WAKEUP 0 #define SENS_INT_WAKEUP0 1 @@ -25,6 +30,11 @@ extern char MAC_ID[15]; #define DEFAULT_COMMS_MODE 1 +<<<<<<< HEAD +======= +#define BUILD_VERSION_STRING "LRSM0009C_Azuma_v0.5" + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void update_checkin_timer(uint64_t checkin_interval); #if (SENS_INT_WAKEUP == 1) void set_periodic_sleep_mode(); diff --git a/main/port.c b/main/port.c index 58532a5..6367c1a 100644 --- a/main/port.c +++ b/main/port.c @@ -24,11 +24,18 @@ static const char* TAG = "PORT"; #define ESP_INTR_FLAG_DEFAULT 0 +<<<<<<< HEAD #define LED_BLUE_PIN 12 #define LED_RED_PIN 13 #define UD_RAD_PWRKEY_PIN 20 #define UD_RAD_RESET_PIN 21 +======= +#define LED_BLUE_PIN 26 +#define LED_RED_PIN 20 +#define LED_GREEN_PIN 21 + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define MODEM_LDO_EN_PIN 33 #define RAD_STATUS_PIN 19 @@ -41,7 +48,11 @@ static const char* TAG = "PORT"; #define ADC_BATT_MON_PIN 1 #define ADC_LIGHT_SEN_PIN 2 +<<<<<<< HEAD #define VBAT_SENSE_EN_PIN 14 +======= +#define VBAT_SENSE_EN_PIN 42 +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define LOWV_DETECT_PIN 38 @@ -54,6 +65,10 @@ extern void IRAM_ATTR push_button_isr(void *args); static bool red_led_status = 0; static bool blue_led_status = 0; +<<<<<<< HEAD +======= +static bool green_led_status = 0; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static void init_outputs(void) { @@ -63,11 +78,15 @@ static void init_outputs(void) io_conf.mode = GPIO_MODE_OUTPUT; io_conf.pin_bit_mask = PIN_MASK(LED_RED_PIN) | \ PIN_MASK(LED_BLUE_PIN) | \ +<<<<<<< HEAD PIN_MASK(UD_RAD_PWRKEY_PIN) | \ PIN_MASK(UD_RAD_RESET_PIN) | \ PIN_MASK(MODEM_LDO_EN_PIN) | \ PIN_MASK(ACCEL_PWN_PIN) | \ /* PIN_MASK(LIGHT_SENSOR_EN_PIN) |*/ +======= + PIN_MASK(LED_GREEN_PIN) | \ +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) PIN_MASK(VBAT_SENSE_EN_PIN); io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; io_conf.pull_up_en = GPIO_PULLUP_DISABLE; @@ -75,6 +94,7 @@ static void init_outputs(void) ESP_ERROR_CHECK(gpio_config(&io_conf)); //Initialize all Outputs to LOW +<<<<<<< HEAD gpio_set_level(LED_RED_PIN, 0); gpio_set_level(LED_BLUE_PIN, 0); gpio_set_level(UD_RAD_PWRKEY_PIN, 0); @@ -82,6 +102,11 @@ static void init_outputs(void) gpio_set_level(MODEM_LDO_EN_PIN, 0); gpio_set_level(ACCEL_PWN_PIN, 0); gpio_set_level(LIGHT_SENSOR_EN_PIN, 0); +======= + gpio_set_level(LED_RED_PIN, 1); + gpio_set_level(LED_BLUE_PIN, 1); + gpio_set_level(LED_GREEN_PIN, 1); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) gpio_set_level(VBAT_SENSE_EN_PIN, 0); } @@ -106,7 +131,11 @@ static void init_inputs(void) static void init_isrs(void) { +<<<<<<< HEAD gpio_config_t io_conf = {0}; +======= + /*gpio_config_t io_conf = {0}; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) io_conf.intr_type = GPIO_INTR_ANYEDGE; io_conf.mode = GPIO_MODE_INPUT; @@ -122,16 +151,27 @@ static void init_isrs(void) gpio_isr_handler_add(ACCEL_INT1_PIN, accel_int1_isr, (void *)ACCEL_INT1_PIN); gpio_isr_handler_add(VUSB_DETECT_PIN, vusb_detect_isr, (void *)VUSB_DETECT_PIN); gpio_isr_handler_add(LOWV_DETECT_PIN, lowv_detect_isr, (void *)LOWV_DETECT_PIN); +<<<<<<< HEAD gpio_isr_handler_add(SWITCH_INPUT_PIN, push_button_isr, (void *)SWITCH_INPUT_PIN); +======= + gpio_isr_handler_add(SWITCH_INPUT_PIN, push_button_isr, (void *)SWITCH_INPUT_PIN);*/ +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } void port_init(void) { init_outputs(); +<<<<<<< HEAD init_inputs(); init_isrs(); gpio_deep_sleep_hold_dis(); +======= +// init_inputs(); +// init_isrs(); + +// gpio_deep_sleep_hold_dis(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*rtc_gpio_init(LED_BLUE_PIN); rtc_gpio_set_direction(LED_BLUE_PIN, RTC_GPIO_MODE_OUTPUT_ONLY); rtc_gpio_pulldown_dis(LED_BLUE_PIN); @@ -141,15 +181,38 @@ void port_init(void) void port_red_led_on(void) { +<<<<<<< HEAD gpio_set_level(LED_RED_PIN, 1); +======= + gpio_set_level(LED_RED_PIN, 0); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) red_led_status = 1; } void port_red_led_off(void) { +<<<<<<< HEAD gpio_set_level(LED_RED_PIN, 0); red_led_status = 0; } +======= + gpio_set_level(LED_RED_PIN, 1); + red_led_status = 0; +} + +void port_green_led_off(void) +{ + gpio_set_level(LED_GREEN_PIN, 1); + green_led_status = 0; +} + +void port_green_led_on(void) +{ + gpio_set_level(LED_GREEN_PIN, 0); + green_led_status = 1; +} + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void port_red_led_toggle(void) { if(red_led_status) @@ -169,12 +232,20 @@ bool port_red_led_is_on(void) void port_blue_led_on(void) { +<<<<<<< HEAD gpio_set_level(LED_BLUE_PIN, 1); +======= + gpio_set_level(LED_BLUE_PIN, 0); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) blue_led_status = 1; } void port_blue_led_off(void) { +<<<<<<< HEAD gpio_set_level(LED_BLUE_PIN, 0); +======= + gpio_set_level(LED_BLUE_PIN, 1); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) blue_led_status = 0; } @@ -200,7 +271,11 @@ bool port_blue_led_is_on(void) return blue_led_status; } +<<<<<<< HEAD void port_modem_assert_pwrkey(void) +======= +/*void port_modem_assert_pwrkey(void) +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) { gpio_set_level(UD_RAD_PWRKEY_PIN, 1); } @@ -208,7 +283,11 @@ void port_modem_assert_pwrkey(void) void port_modem_deassert_pwrkey(void) { gpio_set_level(UD_RAD_PWRKEY_PIN, 0); +<<<<<<< HEAD } +======= +}*/ +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) int port_modem_is_on(void) { diff --git a/main/port.h b/main/port.h index 45f85d4..ffc77c7 100644 --- a/main/port.h +++ b/main/port.h @@ -36,6 +36,12 @@ void port_blue_led_off(void); void port_blue_led_toggle(void); bool port_blue_led_is_on(void); +<<<<<<< HEAD +======= +void port_green_led_on(void); +void port_green_led_off(void); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void port_modem_assert_pwrkey(void); void port_modem_deassert_pwrkey(void); int port_is_usb_connected(void); diff --git a/main/rtc.c b/main/rtc.c index 604be79..8ef0ca4 100644 --- a/main/rtc.c +++ b/main/rtc.c @@ -8,6 +8,22 @@ #include #include #include "esp_sntp.h" +<<<<<<< HEAD +======= +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "lwip/sockets.h" +#include "lwip/err.h" +#include "lwip/netdb.h" +#include "lwip/icmp.h" +#include "esp_system.h" +#include "esp_log.h" +#include +#include +#include +#include "nvm.h" +#include "nvs_flash.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) @@ -32,6 +48,98 @@ static const char* TAG = "RTC"; static bool rtc_set = false; +<<<<<<< HEAD +======= +#define PING_HOST "8.8.8.8" // Google DNS +#define CHECK_INTERVAL 1 //60000 // Check every 60 seconds +#define MAX_DISCONNECT_TIME 5 //86400 // 24 hours in seconds +#define SEC 3600 +static time_t last_successful_ping = 0; + + +/// Internet monitor // + + +time_t get_sntp_time() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec; // Return UNIX timestamp +} + + +bool ping_test() +{ + struct sockaddr_in target_addr; + target_addr.sin_addr.s_addr = inet_addr(PING_HOST); + target_addr.sin_family = AF_INET; + target_addr.sin_port = htons(0); + + int sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); + if (sock < 0) + { + ESP_LOGE(TAG, "Socket creation failed"); + return false; + } + + struct icmp_echo_hdr echo_req; + memset(&echo_req, 0, sizeof(echo_req)); + echo_req.id = htons(1); + echo_req.seqno = htons(1); + echo_req.type = ICMP_ECHO; + + if (sendto(sock, &echo_req, sizeof(echo_req), 0, (struct sockaddr *)&target_addr, sizeof(target_addr)) < 0) + { + ESP_LOGE(TAG, "Ping send failed"); + close(sock); + return false; + } + + fd_set read_fds; + struct timeval timeout = {1, 0}; // 1 second timeout + FD_ZERO(&read_fds); + FD_SET(sock, &read_fds); + + if (select(sock + 1, &read_fds, NULL, NULL, &timeout) > 0) + { + ESP_LOGI(TAG, "Internet is available"); + close(sock); + return true; + } + + ESP_LOGW(TAG, "Ping timeout, no internet"); + close(sock); + return false; +} + + +void internet_monitor_task(void *pvParameter) +{ + while (1) + { + time_t current_time = get_sntp_time(); + + if (ping_test()) + { + last_successful_ping = current_time; + } + + if (last_successful_ping > 0 && (current_time - last_successful_ping) > MAX_DISCONNECT_TIME) + { + ESP_LOGE(TAG, "No internet for %d hours, restarting...", (MAX_DISCONNECT_TIME/SEC)); + /* erase the NVS partition */ + ESP_ERROR_CHECK(nvs_flash_erase()); + esp_restart(); + } + + vTaskDelay(pdMS_TO_TICKS(CHECK_INTERVAL)); // Wait before next check + } +} + + +// END /// + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) int app_rtc_init(void) { int retval = RTC_STATUS_OK; @@ -231,6 +339,7 @@ void time_sync_notification_cb(struct timeval_1 *tv) { } */ +<<<<<<< HEAD void obtain_time(void) { ESP_LOGI(TAG, "Initializing SNTP"); @@ -238,6 +347,64 @@ void obtain_time(void) { sntp_setservername(0, "pool.ntp.org"); // Set NTP server // sntp_set_time_sync_notification_cb(time_sync_notification_cb); sntp_init(); +======= + +void obtain_time(void) { + ESP_LOGI(TAG, "Initializing SNTP"); + + const char *ntp_servers[] = { + "pool.ntp.org", + "time.google.com", + "1.pool.ntp.org" + }; + int server_index = 0; + int num_servers = sizeof(ntp_servers) / sizeof(ntp_servers[0]); + + time_t now = 0; + struct tm timeinfo = { 0 }; + + while (server_index < num_servers) { + ESP_LOGI(TAG, "Using NTP server: %s", ntp_servers[server_index]); + + esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); + esp_sntp_setservername(0, ntp_servers[server_index]); + esp_sntp_init(); + + int retry = 0; + const int max_retries = 10; + + while (timeinfo.tm_year < (2020 - 1900) && retry < max_retries) { + ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry + 1, max_retries); + vTaskDelay(2000 / portTICK_PERIOD_MS); + time(&now); + localtime_r(&now, &timeinfo); + retry++; + } + + if (timeinfo.tm_year >= (2020 - 1900)) { + ESP_LOGI(TAG, "Time synchronized: %s", asctime(&timeinfo)); + + // create internet monitor task + xTaskCreate(&internet_monitor_task, "internet_monitor_task", 4096, NULL, 5, NULL); + return; // Exit the function since time is successfully obtained + } + + ESP_LOGE(TAG, "Failed to sync time with %s, switching to next server...", ntp_servers[server_index]); + esp_sntp_stop(); // Stop SNTP before switching + server_index++; // Move to the next server + } + + ESP_LOGE(TAG, "All NTP servers failed! Check network settings."); +} + +/*void obtain_time(void) { + ESP_LOGI(TAG, "Initializing SNTP"); + + esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); + esp_sntp_setservername(0, "pool.ntp.org"); // Set NTP server + // sntp_set_time_sync_notification_cb(time_sync_notification_cb); + esp_sntp_init(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) // Wait for time to be set time_t now = 0; @@ -257,6 +424,7 @@ void obtain_time(void) { } else { ESP_LOGI(TAG, "Time synchronized"); } +<<<<<<< HEAD } char* get_time(void) { @@ -290,3 +458,32 @@ char* get_time(void) { +======= +}*/ + +void get_time(char *time_str, size_t size) { // Buffer is provided by the caller + time_t now; + struct tm timeinfo; + + time(&now); + // ESP_LOGI(TAG, "Time print start %ld", now); + + localtime_r(&now, &timeinfo); + + const char *weekdays[] = {"0", "1", "2", "3", + "4", "5", "6"}; + + // Format time string + snprintf(time_str, size, "%04d/%02d/%02d_%02d:%02d:%02d_%s", + timeinfo.tm_year + 1900, + timeinfo.tm_mon + 1, timeinfo.tm_mday, + timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, + weekdays[timeinfo.tm_wday]); + + ESP_LOGI(TAG, "Formatted Time: %s", time_str); +} + + + +/////////////////////////////////////////////////////// +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) diff --git a/main/rtc.h b/main/rtc.h index 30b9d0e..d796ec7 100644 --- a/main/rtc.h +++ b/main/rtc.h @@ -77,7 +77,11 @@ uint32_t rtc_get_epoch(void); void rtc_set_epoch(uint32_t epoch); +<<<<<<< HEAD char* get_time(void); +======= +void get_time(char *, size_t ); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) void obtain_time(void); #endif /* MAIN_RTC_H_ */ diff --git a/main/wifi_Client.c b/main/wifi_Client.c index 69f61cf..206c5cb 100644 --- a/main/wifi_Client.c +++ b/main/wifi_Client.c @@ -6,9 +6,20 @@ */ +<<<<<<< HEAD #include #include #include "esp_log.h" +======= +#include +#include +#include +#include +#include "esp_err.h" +#include "esp_log.h" +#include "esp_netif_types.h" +#include "main.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include "nvs_flash.h" #include "esp_event.h" #include "esp_netif.h" @@ -26,6 +37,10 @@ #include "esp_mac.h" #include "data_processing.h" #include "hmi.h" +<<<<<<< HEAD +======= +#include "comms.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #if (WIFI_NEEDED == 1) static const char* TAG = "CLIENT"; @@ -34,6 +49,11 @@ static const char* TAG = "CLIENT"; extern uint32_t g_version; extern uint32_t g_McuUpdate; +<<<<<<< HEAD +======= +char http_resp[512]; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) bool isDataNeeded = false; bool getBinFile; @@ -110,8 +130,14 @@ esp_err_t http_event_handler(esp_http_client_event_t *evt) //output_buffer = (char *)pvPortMalloc(evt->data_len); memcpy(output_buffer, evt->data, evt->data_len); output_buffer[evt->data_len] = 0; +<<<<<<< HEAD isDataNeeded = false; //ESP_LOGI(TAG, "%s\n", output_buffer); +======= + ESP_LOGI(TAG, "%s\n", output_buffer); + strcpy(http_resp, output_buffer); + ESP_LOGI(TAG, "http_resp ==> %s\n", http_resp); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } break; @@ -147,8 +173,14 @@ esp_err_t http_event_handler(esp_http_client_event_t *evt) break; case HTTP_EVENT_REDIRECT: +<<<<<<< HEAD ESP_LOGI(TAG, "HTTP_EVENT_REDIRECTED"); break; +======= + ESP_LOGI(TAG, "HTTP_EVENT_REDIRECT"); + esp_http_client_set_redirection(evt->client); + break; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } return ESP_OK; } @@ -164,21 +196,62 @@ static int sum_digits(int digit) return sum; } +<<<<<<< HEAD +======= + +static bool mac_check_valid(char *message_imei) +{ + //find the length of message imei + int len = strlen(message_imei); + ESP_LOGI(TAG,"Received MAC ID : %s",message_imei); + ESP_LOGI(TAG,"Board MAC ID : %s",MAC_ID); + + //check length of imei field + if (len != 15){ + //invalid IMEI + ESP_LOGW(TAG,"Invalid MAC length"); + return false; + } + if(!strcmp(message_imei,MAC_ID)){ + + ESP_LOGW(TAG,"Valid MAC "); + return true; + } + else{ + ESP_LOGI(TAG,"Message IMEI doesn't match board IMEI"); + return false; + } +} + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static bool imei_check_valid(char *message_imei) { //find the length of message imei int len = strlen(message_imei); int sum = 0; ESP_LOGI(TAG,"IMEI : %s",message_imei); +<<<<<<< HEAD +======= + ESP_LOGI(TAG,"Board IMEI : %s",MAC_ID); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) //check length of imei field if (len != 15){ //invalid IMEI +<<<<<<< HEAD ESP_LOGW(TAG,"Invalid IMEI length"); return false; } if(!strcmp(message_imei,modem_get_imei())){ +======= + ESP_LOGW(TAG,"Invalid MAC length"); + return false; + } + if(!strcmp(message_imei,MAC_ID)){ + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) for(int i = len-1 ; i >= 0; i--) { //check if message imei fields contain numbers (0-9) @@ -191,6 +264,12 @@ static bool imei_check_valid(char *message_imei) // Finding sum of the digits // if digit*2 is a two digit number add the two digits sum += sum_digits(digit); +<<<<<<< HEAD +======= + + ESP_LOGW(TAG,"Sum value = %d",sum); + ESP_LOGW(TAG,"Sum mod value = %d",sum %10); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } else{ @@ -229,7 +308,11 @@ static void wifi_Parse_SP5(char *buf, int len) /*IMEI*/ strret = strtok (NULL," "); strcpy(messageIMEI, strret); +<<<<<<< HEAD ret_sp5 = imei_check_valid(messageIMEI); +======= + ret_sp5 = mac_check_valid(messageIMEI); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) if(ret_sp5 != false){ //ok IMEI ESP_LOGI(TAG,"Fetched IMEI matches board"); @@ -251,9 +334,19 @@ static void wifi_Parse_SP5(char *buf, int len) strret = strtok(NULL, "FW_"); strcpy(firmware_version,strret); new_fw_version = (uint32_t)atoi(firmware_version); +<<<<<<< HEAD ESP_LOGI(TAG,"Firmware version from SP5: %ld\nBoard Firmware version: %ld",new_fw_version,g_version); //logging/printing FR_version message for tracing /**********************************************************************************************************/ +======= + ESP_LOGI(TAG,"Firmware version from SP5: %lu\nBoard Firmware version: %lu",new_fw_version,g_version); //logging/printing FR_version message for tracing + + /**********************************************************************************************************/ + + // test version + new_fw_version = 1; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /*check if the new version is greater than current version*/ if(!(new_fw_version > g_version)) { @@ -268,6 +361,10 @@ static void wifi_Parse_SP5(char *buf, int len) getBinFile = true; /*reading OTA files*/ } +<<<<<<< HEAD +======= + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } @@ -363,6 +460,10 @@ static void http_client_get_task(void *pvParameters) .url = (const char*)url, // Replace with your desired URL .method = HTTP_METHOD_GET, .cert_pem = NULL, +<<<<<<< HEAD +======= + .user_data = http_resp, +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) .event_handler = http_event_handler }; @@ -429,10 +530,37 @@ esp_err_t http_client_get(const char *url1, char *response) { vTaskDelay(10 / portTICK_PERIOD_MS); } +<<<<<<< HEAD return http_client_get_err; } +======= + isDataNeeded = false; + return http_client_get_err; +} + +esp_err_t http_get_response_buf(char* bufptr, int len) +{ + if (bufptr && len) + { + uint16_t buf_len = strlen(http_resp); + ESP_LOGI(TAG, "output_buffer => : %s\n",output_buffer); + ESP_LOGI(TAG, "http_resp => : %s\n",http_resp); + ESP_LOGI(TAG, " buf len %d", buf_len); + if (http_resp && buf_len > 0) { + strcpy(bufptr, http_resp); + // *bufptr = output_buffer; + len = buf_len; + ESP_LOGI(TAG, "BUF: %s\nLEN : %d", bufptr, len); + return ESP_OK; + } + bufptr = 0; + len = 0; + } + return ESP_FAIL; +} +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) esp_err_t http_client_do_get_request(get_req_type_t target_url, char* device_imei, char *response_buf) { @@ -461,8 +589,12 @@ esp_err_t http_client_do_get_request(get_req_type_t target_url, char* device_ime if(selected_server == SERVER_TWO) { sprintf(server_url, MCU_GET_CONFIG_FLAGS_URL2, device_imei); +<<<<<<< HEAD retval = http_client_get((const char*)MCU_GET_CONFIG_FLAGS_URL2,response_buf); +======= + http_client_get((const char*)server_url,response_buf); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) if(retval != WIFI_OK) { selected_server = SERVER_THREE; @@ -474,8 +606,12 @@ esp_err_t http_client_do_get_request(get_req_type_t target_url, char* device_ime if(selected_server == SERVER_THREE) { sprintf(server_url, MCU_GET_CONFIG_FLAGS_URL3, device_imei); +<<<<<<< HEAD // http_client_get((const char*)server_url,response_buf); retval = http_client_get((const char*)MCU_GET_CONFIG_FLAGS_URL3,response_buf); +======= + http_client_get((const char*)server_url,response_buf); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) if(retval != WIFI_OK) { selected_server = SERVER_ONE; @@ -563,6 +699,10 @@ esp_err_t http_client_do_get_request(get_req_type_t target_url, char* device_ime break; default: +<<<<<<< HEAD +======= + break; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } return retval; diff --git a/main/wifi_Client.h b/main/wifi_Client.h index c7027ce..e5e3582 100644 --- a/main/wifi_Client.h +++ b/main/wifi_Client.h @@ -38,6 +38,11 @@ esp_err_t http_client_post(char *url, char *params, char *response); void http_client_post_stop(void); esp_err_t http_client_get(const char *url1, char *response); +<<<<<<< HEAD +======= +esp_err_t http_get_response_buf(char* bufptr, int len); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) esp_err_t http_client_do_get_request(get_req_type_t target_url, char* device_imei, char *response_buf); esp_err_t http_client_do_post_request(char *post_params, char *response_buf); void wifi_set_post_str_type(deviceToServer_msgType_t str);; diff --git a/main/wifi_Init.c b/main/wifi_Init.c index 3bcbb92..c1a0284 100644 --- a/main/wifi_Init.c +++ b/main/wifi_Init.c @@ -20,6 +20,10 @@ #include "main.h" #include "nvm.h" #include "data_processing.h" +<<<<<<< HEAD +======= +#include "port.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #if (WIFI_NEEDED == 1) static const char* TAG = "WIFI"; @@ -35,7 +39,11 @@ static const char* TAG = "WIFI"; #define WIFI_AP_DISCONNECTED_BIT BIT4 #define WIFI_DISCONNECTED_BIT BIT5 +<<<<<<< HEAD #define WIFI_AP_SSID "Sensor Setup " +======= +#define WIFI_AP_SSID "Azuma Wifi Setup " +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static char g_pWifiSsidA[MAX_SSID_LEN]; static char g_pWifiPasswordA[MAX_PASSPHRASE_LEN]; @@ -66,6 +74,14 @@ static bool set_wifi_bits; static int s_retry_num = 0; static bool turnOffStation; +<<<<<<< HEAD +======= +int qmtopen_retries = 0; +bool qmtopen_fail = false; +bool qmtclose_fail = false; +bool cops_fail = false; + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) /* This structure holds the WIFI configurations (modes, ip's, ssid&pwd ...etc )*/ esp_netif_t *sta_netif; esp_netif_t *ap_netif; @@ -302,6 +318,10 @@ esp_err_t Connect_wifi_sta(uint8_t mode) void Wifi_Init_SoftAp(void) { +<<<<<<< HEAD +======= + port_red_led_on(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) char ap_ssid[32]; char mac_str[15]; uint8_t mac_base[6] = {0}; diff --git a/main/wifi_Init.h b/main/wifi_Init.h index b723161..8277da8 100644 --- a/main/wifi_Init.h +++ b/main/wifi_Init.h @@ -21,6 +21,13 @@ typedef enum #define STORING_TO_NVM +<<<<<<< HEAD +======= +#define WIFI_STATUS_OK 0 +#define WIFI_STATUS_ERROR -1 +#define WIFI_STATUS_TIMEOUT -2 +#define WIFI_STATUS_MQTT_PUB_OVERFLOW -10 +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define WIFI_CLIENT_MODE 1 #define WIFI_AP_MODE 2 diff --git a/main/wifi_OTA.c b/main/wifi_OTA.c index f9e1e64..b02586f 100644 --- a/main/wifi_OTA.c +++ b/main/wifi_OTA.c @@ -23,6 +23,10 @@ #include "main.h" #include "comms.h" #include "wifi_OTA.h" +<<<<<<< HEAD +======= +#include "comms.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #define BUFFSIZE 1024 #define HASH_LEN 32 /* SHA-256 digest length */ diff --git a/main/wifi_webServer.c b/main/wifi_webServer.c index 68b6fb4..97c64c8 100644 --- a/main/wifi_webServer.c +++ b/main/wifi_webServer.c @@ -24,8 +24,13 @@ #include "hmi.h" #include "nvm.h" #include "modem.h" +<<<<<<< HEAD #include "i2c_sensors.h" #include "mbedtls/base64.h" +======= +#include "mbedtls/base64.h" +#include "port.h" +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #include #include @@ -197,7 +202,11 @@ char *url_decode(char *str) #ifdef BOARD_TEST const char *main_resp = " Temp Stick Setup - Ideal Sciences

Temp Stick Setup

Step 1 Select WiFi Network
Step 2 Test Connection
Step 3 Complete

Select a WiFi Network

(Leave blank if no password required)

Test Connection

Give us about 30 seconds as we test your WiFi connection

WiFi Setup Complete

The sensor successfully connected to your WiFi network

Let's assign your sensor to an Ideal Sciences account:

-or-


Create Account

Login

The email and/or password you submitted is incorrect.

Account Setup Complete


SENSOR ID:

MAC ADDR:

Board Testing

Battery
Light
ENS210
MC3419
MCP9600T
BG77

LEDs

"; #else +<<<<<<< HEAD const char *main_resp = "WiFi Switch Setup - Azuma

Temp Stick Setup

Step 1 Select WiFi Network
Step 2 Test Connection
Step 3 Complete

Select a WiFi Network

Enter Custom SSID (Hidden Networks)

(Leave blank if no password required)

Test Connection

Give us about 30 seconds as wetest your WiFi connection

WiFi Setup Complete

The sensor successfully connected to your WiFi network


SENSOR ID:

MAC ADDR:

"; +======= +const char *main_resp = "WiFi Switch Setup - Azuma

Azuma WiFi Setup

Step 1 Select WiFi Network
Step 2 Test Connection
Step 3 Complete

Select a WiFi Network

Enter Custom SSID (Hidden Networks)

(Leave blank if no password required)

Test Connection

Give us about 30 seconds as wetest your WiFi connection

WiFi Setup Complete

The sensor successfully connected to your WiFi network


SENSOR ID:

MAC ADDR:

"; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) //const char* main_resp = "Temp Stick Setup - Ideal Sciences

Temp Stick Setup

Step 1Select WiFi Network
Step 2Test Connection
Step 3Complete

Select a WiFi Network

(Leave blank if no password required)

Test Connection

Give us about 30 seconds as we test your WiFi connection


"; #endif @@ -265,7 +274,11 @@ static const httpd_uri_t ki_min_js_t = { +<<<<<<< HEAD const char *style = "body{font-family: Arial, sans-serif; background-color: #eaeaea; padding: 0; margin: 0;}h2{margin: 0 0 10px 0;}label{display: block; margin: 10px 0px;}button{font-size: 18px; font-family: DroidSans, Arial, sans-serif; border: 0; background-color: #0b5bb5; color: #fff; padding: 15px; cursor: pointer; display: block; width: 100%;}button:disabled{background-color: #eaeaea; color:#aaaaaa; cursor:not-allowed;}.header{padding: 15px 0; background: #111; color: #fff; margin-bottom: 8px;}.header h1{font-size:26px; line-height: 26px; font-weight: bold; margin: 0; text-align: center;}.container{padding: 15px;}#setup-steps{list-style-type: none; padding: 0px; margin: 0px; position: relative;}#setup-steps li{position: absolute; display: inline-block;}#setup-steps li span{padding: 10px; font-size: 18px; background-color: #a8a8a8; color: white; font-weight: normal; border-radius: 20px; min-width: 20px; display: inline-block; text-align: center;}#setup-steps li.active span{/*background-color: #7ed600;*/ background-color: #0b5bb5; font-weight: bold;}#setup-step-1{left:0px;}#setup-step-2{left:42%;}#setup-step-3{right:0px;}input:not([type=\"radio\"]):not([type=\"checkbox\"]), select{font-size: 18px; font-family: DroidSans, Arial, sans-serif; padding: 10px; width: 95%}input[type=\"checkbox\"]{float: left; margin-right: 10px;}.col_50{width: 49%; display: inline-block;}.section{transition: margin-left ease-in 0.5s}.step_name{display: inline-block; min-width: 260px; background-color: #a8a8a8; color: white; padding: 10px; display: inline-block; text-shadow: 1px 1px 1px black; position: relative;}.step_name.active{background-color: #7ed600}.show-for-medium-down{display:none;}@media screen and (max-width: 800px){.col_50{width: 100%; display: block; margin-bottom: 15px;}.section{width: 100%; max-width: 100% !important;}.show-for-medium-down{display:block;}}@media screen and (max-width:1023px){.hide_for_medium_down{display:none;}}.step_name .step_num{font-weight: bold; font-size: 30px; text-transform: uppercase;}.step_name .step_label{position: absolute; right: 15px; top: 18px;}.align-top{vertical-align: top;}.loader{content:url('data:image/gif;base64,R0lGODlhFAAUAKUAACRqvIy23Mza7GSWzOTu9KzG5Hym1PT6/Dx+xLzS7Jy65Nzm9Gye1PT2/NTi9Oz2/ISu3EyKzMTa7Dx6xJS23Mze7Gya1Ozy/LTO7Pz6/MTW7KTC5HSe1CRuvGSa1OTu/LTK5ISq3ER+xLzW7KS+5OTq9Iyy3FSOzJS63Mze9Pz+/HSi1P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQICgAAACwAAAAAFAAUAAAGwECWcDgMUIhIIkHREDJWwothkRQuLBshB8qCTFJVIYpRYj1ZDgSXeKGyLgxTN6TyiMosibsAKVxYBRgZQhkKCiwLAwAWQg0gEBAjVSomHR0rf0MEJJJVECcOYSphGYNDIyCBCWFCEROvAwmpIBisLK6wSKOTYQ8CoVULEk1DBw60bkkOCRgOphUgKU0LDrsq1CwHAhgVjZkHGAIsAmASCcQXxETbTSMab9ysF81CGu9oGJlJDRWm9kLa1NmqAKxKEAAh+QQICgAAACwAAAAAFAAUAIUMWrSErtzE2uxUjszk6vSsyuR0ntTs9vxEgsScuuTU4vRkmtQkary80uz8+vzM2uzs8vwUYrSUutxklszk7vS0yuR8ptT09vykwuRsmtTM3uwMXrSMstxcksycvuTc5vQkbrzE1uz8/vzk7vy0zuyEqtz0+vxsntTM3vT///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGxsCUcDgsVIhIIqRhEiYSwkuCkhRSPCEnNOU5farChgeSkkA/py3xQk5BPKQUBiOSnNoKakpD0lz2Gg5CIhVHFCUDHEIOKCQkX0kiGAMDCW1RApBJGBaaSCJggkQoIaUaYEIGHR0TFhqlIaeoJxOrAZ9gJqBJBw8KYBwDv0MmChWPVSIcICAWbRoVKH8fCrsOFiUpHxMMGVFtJiQPKQ8oIggRkJlJDyR/DVkPAAOoECTDpUILAAJgF4FC8qWg0GEYKiEaDCYJAgAh+QQICgAAACwAAAAAFAAUAIUMWrSErtzE2uxMhsTk6vRsmtSsxuTs9vycuuRcksw8esTU4vR8ptRcjsz8+vyUttzM2uxUjszs8vy80uykwuREgsQUXrRUiszk7vR0otT09vykvuRkmtREfsSEqtzM3uwMXrSMstxMhsxsntS0zuycvuRklsw8fsTc5vR8qtT8/vyUutzE1uzk7vz0+vzM3vT///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGv0CYcDh8LYhIoubjELJYQtdEkhRKSEfY01nCVIUfkkYLxZQmSQ0VpiFBYIIPjLQ5CAnr8GeMWqiEDh9yEhQBBoAvJCQoXxMBAWJKAoxVExteVX+ZSC9PLHJfMA+PARsfnqBfo48bSJpJTVUHEFlJFCmUUQuKuUQqFA0RK2MwYRBjKR4ugAgIMBgBFyFCakIoIAMOCSYqHB2UC5hEFyAvMCIiMAsnGaEsAAVCFekwHgq1SAsRawP0Egy9Qo1o9yUIACH5BAgKAAAALAAAAAAUABQAhSRqvIy23Mza7FySzOTu9KzG5Hym1PT6/Dx+xNzm9Gye1LzS7Jy65PT2/NTi9Gya1Oz2/ISu3FSKzDx6xJS23Mze7GSa1Ozy/LTO7Pz6/OTq9HSe1MTa7CRuvGSW1OTu/LTK5ISq3ER+xNzq9MTW7KTC5Iyy3FSOzJS63Mze9Pz+/HSi1P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAbEQJZwOEw5iEhio5IRkkjCQ6WRFF4wR9ZT6MBcqsIKhrqFgCrJxpfVwAhYHDRnQWVd6uIpK+FQCVV8bHlCGSkYGAlgXVhNQw0ciVUJHHVJflWXQwMTnBJgQhggBRgkHpwTnp8YowVQQyqNSQeKJyZgCyUERBcrAB0mmUQLJiFjQh4AHiMsDAyNKiAYdiURBUIJbywjCAosIREqJgprI2tEKwiJCissGg8MnxUTEUIb7CwlD5FJIwZr9kIgMND1aUgACp+CAAAh+QQICgAAACwAAAAAFAAUAIUMWrSErtzE2uxUiszk6vSsyuRsntScuuTs9vzc5vRkltREgsQkaryMttzU4vS80ux8ptT8+vzM2uxckszs8vykwuQUXrRcjszk7vS0yuSkvuT09vxsmtSUttyEqtzM3uwMXrSMstxUjsx0otScvuTc6vRkmtQkbrzE1ux8qtT8/vzk7vy0zuz0+vyUutzM3vT///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGvUCYcDh8OYhIouNCEaJQwtZnk3QCOE4ozMFqVmED0Av2hCEyn2RCInRYFirJWPCgwih2E0NRgqU8LUIqCUcbHyxpdyMMJyEqVQksLA4RSiIhXwkCXkgqlVWPRB4TEwojX0ISTygvKQqkp6gvq0dDnl+hahAVmQJ2QhQdIhO8kJKUQiEiARgwGSyfcWOGiEIEtSsGDTAVvCwaCMC/QwccBDAHB3ckD6gJHMUu6mQkzVUYJHbpUQ+cqDAFMqAKAgAh+QQICgAAACwAAAAAFAAUAIUMWrSErtzE2uxMhsTk6vSsxuRsmtTs9vycuuQ8esTc5vRcksy80uzU4vR8ptT8+vyUttzM2uxcjszs8vykwuREgsQUYrRUjszk7vS0zux0otT09vykvuREfsTE1uzM3uwMXrSMstxMhsy0yuRsntScvuQ8fsTc6vRkmtS81uyEqtz8/vyUutzk7vz0+vzM3vT///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGwUCYcDgkaYhI4skxEQ5EQoykkRS+EgEnFIYCCKpCjUkBq0AjoEuSQIURTAbYYrGqWMiwyUYYugQwMAgIK0IuKg4wLhEZH0ITEBcSFIRIKwoZGQ0PRAoOFGAKAntJK5tVlEMlAasIYEIfHrEvqqyuMBGxHm1DqEimSRgcKaCiRBsjqx5gDQyZpgUBBU0fH5SWVBsfjI4njiUjtxEwAhkujqNEDCVNsTAHDOJgGCXKMO0w2k1VEwzm9vUuPqCz9WFXkiAAOzhzTTFRUytROC9ESnl3ODZPR05pdUFRdkRLdlFTM3FwWDVaSnhUdytxN243cEtNVFFNNWo3cmV3YjRsa1EvTjE=');}.hide{display:none;}.button_account{background-color: white; color: #444; padding: 10px 8px; border: 1px solid #444; margin-right: 15px;}.button_account.active{background-color: #0b5bb5; color:white;}.red{color:red;}"; +======= +const char *style = "body { font-family: Arial, sans-serif; background-color: #eaeaea; padding: 0; margin: 0; } h2 { margin: 0 0 10px 0; } label { display: block; margin: 10px 0px; } button { font-size: 18px; font-family: DroidSans, Arial, sans-serif; border: 0; background-color: #0b5bb5; color: #fff; padding: 15px; cursor: pointer; display: block; width: 100%; } button:disabled { background-color: #eaeaea; color: #aaaaaa; cursor: not-allowed; } .header { padding: 15px 0; background: #111; color: #fff; margin-bottom: 8px; } .header h1 { font-size: 26px; line-height: 26px; font-weight: bold; margin: 0; text-align: center; } .container { padding: 15px; } #setup-steps { list-style-type: none; padding: 0px; margin: 0px; position: relative; } #setup-steps li { position: absolute; display: inline-block; } /* #setup-steps li span { padding: 10px; font-size: 18px; background-color: #a8a8a8; color: white; font-weight: normal; border-radius: 20px; min-width: 20px; display: inline-block; text-align: center; */ } #setup-steps li.active span { /*background-color: #7ed600;*/ background-color: #0b5bb5; font-weight: bold; } #setup-step-1 { left: 0px; } #setup-step-2 { left: 42%; } #setup-step-3 { right: 0px; } input:not([type=\"radio\"]):not([type=\"checkbox\"]), select { font-size: 18px; font-family: DroidSans, Arial, sans-serif; padding: 10px; width: 95% } input[type=\"checkbox\"] { float: left; margin-right: 10px; } .col_50 { width: 49%; display: inline-block; } .section { transition: margin-left ease-in 0.5s } .step_name { display: inline-block; min-width: 260px; background-color: #a8a8a8; color: white; padding: 10px; display: inline-block; text-shadow: 1px 1px 1px black; position: relative; } .step_name.active { background-color: #7ed600 } .show-for-medium-down { display: none; } @media screen and (max-width: 800px) { .col_50 { width: 100%; display: block; margin-bottom: 15px; } .section { width: 100%; max-width: 100% !important; } .show-for-medium-down { display: block; } } @media screen and (max-width:1023px) { .hide_for_medium_down { display: none; } } .step_name .step_num { font-weight: bold; font-size: 30px; text-transform: uppercase; } .step_name .step_label { position: absolute; right: 15px; top: 18px; } .align-top { vertical-align: top; } .loader { content: url('data:image/gif;base64,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'); } .hide { display: none; } .button_account { background-color: white; color: #444; padding: 10px 8px; border: 1px solid #444; margin-right: 15px; } .button_account.active { background-color: #0b5bb5; color: white; } .red { color: red; }"; +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) static esp_err_t style_css_handler(httpd_req_t *req) { /* Respond with empty body */ @@ -977,11 +990,19 @@ static esp_err_t readSensors_handler(httpd_req_t *req) response[0] = 0; safeStrCat(response, sizeof(response), (char*)"{\"tempC\":"); +<<<<<<< HEAD sprintf(floatStr, "%.2f", get_temperature_data()); safeStrCat(response, sizeof(response), floatStr); safeStrCat(response, sizeof(response), (char*)"{,\"humidity\":"); sprintf(floatStr, "%.2f", get_humidity_data()); +======= + + safeStrCat(response, sizeof(response), floatStr); + + safeStrCat(response, sizeof(response), (char*)"{,\"humidity\":"); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) safeStrCat(response, sizeof(response), floatStr); safeStrCat(response, sizeof(response), (char*)"}"); @@ -1111,6 +1132,10 @@ void startOnboarding(void *pvParameters) if(g_onboardingCompleted || g_wlanOnboardingDone) { ESP_LOGI(TAG,"On-boarding complete."); +<<<<<<< HEAD +======= + port_red_led_off(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #ifdef STORING_TO_NVM /* Store the wifi-onboarded flag in nvs */ @@ -1166,7 +1191,11 @@ void startOnboarding(void *pvParameters) case WLAN_WIFI_WAITING_TO_CONNECT: if(wifi_station_connected()) { +<<<<<<< HEAD ESP_LOGI(TAG,"\nConnected to WiFi on channel: %d",data_get_wifi_channel()); +======= +// ESP_LOGI(TAG,"\nConnected to WiFi on channel: %d",data_get_wifi_channel()); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) // Save AP's MAC address //data_set_ap_mac_addr(data_get_ap_mac_addr()); @@ -1448,8 +1477,16 @@ void webserver_stop(httpd_handle_t server) void webserver_start(void) { +<<<<<<< HEAD #ifdef STORING_TO_NVM device_wifi_onboarded = nvm_read_onboarding_flag(WIFI_ONBOARDING_KEY); +======= + + +#ifdef STORING_TO_NVM + device_wifi_onboarded = nvm_read_onboarding_flag(WIFI_ONBOARDING_KEY); + port_red_led_off(); +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) #endif if(!device_wifi_onboarded) @@ -1457,10 +1494,21 @@ void webserver_start(void) wifi_first_init(); Wifi_Init_SoftAp(); xTaskCreate(startOnboarding, "onboarding_task", 8192, NULL, 16, NULL); +<<<<<<< HEAD +======= + port_red_led_off(); + + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } else { g_onboardingCompleted = true; +<<<<<<< HEAD +======= + port_red_led_off(); + +>>>>>>> 4ea13f8 (Added azuma wifi switch backup code) } }