ruuvi / ruuvi.gateway_esp.c

Ruuvi Gateway ESP32 code
BSD 3-Clause "New" or "Revised" License
24 stars 15 forks source link

HTTPS request to check for firmware updates performed before time synchronisation is complete after initial network connection #924

Open TheSomeMan opened 7 months ago

TheSomeMan commented 7 months ago
I (118293) http_server: [http_server/1] Request from 10.10.0.2 to 10.10.0.1 (Host: 10.10.0.1): POST /connect.json
I (118296) http_server: [http_server/1] POST /connect.json, params=
I (118301) http_server: [http_server/1] http_server_netconn_serve: POST /connect.json
I (118309) http_server: [http_server/1] POST /connect.json: SSID:WIFI786_2.4G, PWD: ******** - connect to WiFi
I (118320) wifi_manager: [http_server/1] wifi_manager_connect_async: wifiman_msg_send_cmd_connect_sta: CONNECTION_REQUEST_USER
I (118332) wifi_manager: [http_server/1] Send msg: ORDER_CONNECT_STA, conn_req_code=1
I (118340) wifi_manager: [wifi_manager/5] MESSAGE: ORDER_CONNECT_STA: CONNECTION_REQUEST_USER, event_bits=0x0c15
I (118351) wifi_manager: [wifi_manager/5] WIFI_MANAGER:EV_STATE: Set WIFI_MANAGER_REQUEST_STA_CONNECT_BIT
I (118361) wifi_manager: [wifi_manager/5] WIFI_MANAGER:EV_STATE: Clear WIFI_MANAGER_REQUEST_DISCONNECT_BIT
I (118644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 5
I (118995) dns_server: [dns_server/4] Replying to DNS request for 2-courier.push.apple.com from 10.10.0.2
I (119004) dns_server: [dns_server/4] Replying to DNS request for 2-courier.push.apple.com from 10.10.0.2
I (119040) wifi:new:<6,0>, old:<6,0>, ap:<6,0>, sta:<6,0>, prof:6
I (119528) wifi:state: init -> auth (b0)
I (119535) http_server: [http_server/1] Json resp: code=200, content:
{}
I (119537) http_server: [http_server/1] Response: OK
I (119555) dns_server: [dns_server/4] Replying to DNS request for 20-courier.push.apple.com from 10.10.0.2
I (119557) dns_server: [dns_server/4] Replying to DNS request for 20-courier.push.apple.com from 10.10.0.2
I (119571) http_server: [http_server/1] Request from 10.10.0.2 to 10.10.0.1 (Host: 10.10.0.1): GET /status.json
I (119576) wifi:state: auth -> assoc (0)
I (119581) network: [http_server/1] callback: cb_on_request_status_json
I (119586) ruuvi_gateway: [http_server/1] ### Start timer for deactivation of configuration mode after timeout (60 seconds)
I (119597) wifi:state: assoc -> run (10)
I (119603) http_server: [http_server/1] Json resp: code=200, content:
{}

I (119610) http_server: [http_server/1] Response: OK
I (119644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 5
I (119698) wifi:connected with WIFI786_2.4G, aid = 18, channel 6, BW20, bssid = 66:20:e0:12:b8:2e
I (119699) wifi:security: WPA2-PSK, phy: bgn, rssi: -15
I (119702) wifi:pm start, type: 0

I (119709) wifi_manager: [sys_evt/20] WIFI_EVENT_STA_CONNECTED
I (119742) dns_server: [dns_server/4] Replying to DNS request for 0-courier.push.apple.com from 10.10.0.2
I (119744) dns_server: [dns_server/4] Replying to DNS request for 0-courier.push.apple.com from 10.10.0.2
I (119801) wifi:AP's beacon interval = 409600 us, DTIM period = 1
I (119927) dns_server: [dns_server/4] Replying to DNS request for 9-courier.push.apple.com from 10.10.0.2
I (119930) dns_server: [dns_server/4] Replying to DNS request for 9-courier.push.apple.com from 10.10.0.2
I (120229) ruuvi_gateway: [main/1] free heap: 112692
I (120644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 7
I (120656) http_server: [http_server/1] Request from 10.10.0.2 to 10.10.0.1 (Host: 10.10.0.1): GET /status.json
I (120657) network: [http_server/1] callback: cb_on_request_status_json
I (120663) ruuvi_gateway: [http_server/1] ### Start timer for deactivation of configuration mode after timeout (60 seconds)
I (120675) http_server: [http_server/1] Json resp: code=200, content:
{}

I (120683) http_server: [http_server/1] Response: OK
I (121131) esp_netif_handlers: sta ip: 192.168.1.147, mask: 255.255.255.0, gw: 192.168.1.1
I (121132) wifi_manager: [sys_evt/20] IP_EVENT_STA_GOT_IP
I (121136) wifi_manager: [wifi_manager/5] MESSAGE: EVENT_STA_GOT_IP
I (121143) wifi_manager: [wifi_manager/5] WIFI_MANAGER:EV_STATE: Clear WIFI_MANAGER_REQUEST_STA_CONNECT_BIT | WIFI_MANAGER_REQUEST_RESTORE_STA_BIT
I (121157) ruuvi_gateway: [wifi_manager/5] ruuvi_cb_on_change_cfg: settings_save_to_flash
I (121230) settings: [wifi_manager/5] ### Save config to NVS: successfully updated
I (121231) ruuvi_gateway: [wifi_manager/5] ruuvi_cb_on_change_cfg: http_server_set_auth: lan_auth_default
I (121239) wifi_manager: [wifi_manager/5] WIFI_MANAGER:EV_STATE: Set WIFI_MANAGER_WIFI_CONNECTED_BIT
I (121248) wifi_manager: [wifi_manager/5] Set STA IP String to: 192.168.1.147
I (121256) wifi_manager: [wifi_manager/5] DHCP IP: 192.168.1.1
I (121262) network: [wifi_manager/5] Wifi connected
I (121268) ADV_POST_TASK: [adv_post_task/5] Handle event: NETWORK_CONNECTED
I (121275) ADV_POST_TASK: [adv_post_task/5] Force pending advs1 retransmission
I (121284) TIME: [time_task/1] ### Activate SNTP time synchronization
I (121285) ruuvi_gateway: [main/1] ### Handle event: NETWORK_CONNECTED
I (121302) ruuvi_gateway: [main/1] ### Start mDNS: Hostname: "RuuviGateway4FAD", Instance: "RuuviGateway4FAD"
I (121644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 6
I (121717) http_server: [http_server/1] Request from 10.10.0.2 to 10.10.0.1 (Host: 10.10.0.1): GET /status.json
I (121719) network: [http_server/1] callback: cb_on_request_status_json
I (121725) ruuvi_gateway: [http_server/1] ### Start timer for deactivation of configuration mode after timeout (60 seconds)
I (121737) http_server: [http_server/1] Json resp: code=200, content:
{"ssid":"WIFI786_2.4G","ip":"192.168.1.147","netmask":"255.255.255.0","gw":"192.168.1.1","dhcp":"192.168.1.1","urc":0}

I (121755) http_server: [http_server/1] Response: OK
I (121834) http_server: [http_server/1] Request from 10.10.0.2 to 10.10.0.1 (Host: 10.10.0.1): GET /firmware_update.json
I (121836) http_download: [http_server/1] HTTP download/check: Method=GET, URL: 'https://network.ruuvi.com/firmwareupdate'
I (121847) gw_status: [http_server/1] SUSPEND RELAYING
I (121854) esp-tls: [http_server] esp_tls_init: tls=0x3ffe5fd4
I (121876) esp-tls: [tiT] esp_tls_low_level_conn_callback_dns_found: resolved successfully
I (121912) esp-tls: [http_server] hostname 'network.ruuvi.com' resolved to 3.64.156.170
I (122454) esp-x509-crt-bundle: Certificate validated
I (122644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 6
I (123644) ADV_POST_TASK: [adv_post_task/5] Advs cnt: 4
I (123875) http_download: [http_server/1] HTTP_EVENT_HEADER_SENT
I (124102) TIME: [tiT/18] ### Time has been synchronized: 2023-11-21 05:40:27.532
I (124103) TIME: [tiT/18] Switch time sync mode to SMOOTH
I (124107) ADV_POST_TASK: [adv_post_task/5] Remove all accumulated data with zero timestamps
I (124115) ADV_POST_TASK: [adv_post_task/5] Clear adv_table
I (124122) ADV_POST_TASK: [adv_post_task/5] Force pending advs1 retransmission
E (124130) esp-tls-mbedtls: read error :-26624:
E (124136) TRANS_SSL: esp_tls_conn_read error, errno=26624 (SSL - The operation timed out)
E (124144) http: [http_server/1] ./main/http.c:339 {http_wait_until_async_req_completed}: esp_http_client_perform failed, err=28676 (ESP_ERR_HTTP_FETCH_HEADER)
E (124159) http: [http_server/1] ./main/http.c:351 {http_wait_until_async_req_completed}: esp_http_client_perform failed, err=28676 (ESP_ERR_HTTP_FETCH_HEADER)
I (124174) http_download: [http_server/1] HTTP_EVENT_DISCONNECTED
I (124180) TRANS_SSL: [http_server] ssl_close: tls=0x3ffe5fd4
I (124187) esp-tls: [http_server] esp_tls_conn_destroy: tls=0x3ffe5fd4
I (124198) gw_status: [http_server/1] RESUME RELAYING
E (124200) http_download: [http_server/1] ./main/http_download.c:538 {http_download_json}: http_download failed for URL: https://network.ruuvi.com/firmwareupdate, resp_code=502, content: Network error when communicating with the server, err=28676, description=ESP_ERR_HTTP_FETCH_HEADER
I (124226) http_download: [http_server/1] http_download_json: completed within 2390 ticks
E (124234) http_server: [http_server/1] ./main/http_server_cb_on_get.c:75 {http_server_resp_json_firmware_update}: Failed to download firmware update info: http_resp_code=502, message: Network error when communicating with the server, err=28676, description=ESP_ERR_HTTP_FETCH_HEADER
W (124261) http_server: [http_server/1] Response: status 504 (Gateway timeout)