G-Two / smoke-x-receiver

An ESP32+LoRa application to bridge a ThermoWorks Smoke X remote thermometer to Home Assistant via MQTT
MIT License
14 stars 5 forks source link

MQTTS not working / unable to configure #7

Closed fastbytes closed 1 year ago

fastbytes commented 1 year ago

Firstly, this is fantastic work! This is working with my Smoke X4 and TTGO Lora32 V1 with some minor changes. Few those new to ESP-IDF, be sure to set your XTAL and CPU frequency, otherwise baud rates and wifi will not work.

However, I couldn't get MQTT working. If the URI is defined as mqtt://some.ip.add.ress, then there are errors in logs stating that mqtts wasn't used but there are ssl related parameters configured. Once configured as mqtts (yes, confirmed SSL certs and CA Cert was setup correctly), then I get There are no transports valid, stop mqtt client.

I was able to get past this using mqtt (without 's') and then removing .cert_pem = app_mqtt_params.ca_cert from app_web_ui.c, but it feels like a step backwards and that I'm missing something.

Is there something else that needs to be configured here?

Screenshot 2022-09-12 223342

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7200
load:0x40078000,len:14884
ho 0 tail 12 room 4
load:0x40080400,len:3716
entry 0x40080680
I (30) boot: ESP-IDF v4.4.2 2nd stage bootloader
I (30) boot: compile time 20:47:34
I (31) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (44) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 4MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00200000
I (92) boot:  3 storage          Unknown data     01 82 00210000 00100000
I (100) boot: End of partition table
I (104) boot_comm: chip revision: 1, min. application chip revision: 0
I (111) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=20478h (132216) map
I (168) esp_image: segment 1: paddr=000304a0 vaddr=3ffb0000 size=03a74h ( 14964) load
I (174) esp_image: segment 2: paddr=00033f1c vaddr=40080000 size=0c0fch ( 49404) load
I (194) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=aa14ch (696652) map
I (447) esp_image: segment 4: paddr=000ea174 vaddr=4008c0fc size=09958h ( 39256) load
I (463) esp_image: segment 5: paddr=000f3ad4 vaddr=50000000 size=00010h (    16) load
I (474) boot: Loaded app from partition at offset 0x10000
I (474) boot: Disabling RNG early entropy source...
I (486) cpu_start: Pro cpu up.
I (486) cpu_start: Starting app cpu, entry point is 0x40081258
0x40081258: call_start_cpu1 at /home/******/esp/esp-idf-v4.4.2/components/esp_system/port/cpu_start.c:160

I (0) cpu_start: App cpu up.
I (502) cpu_start: Pro cpu start user code
I (502) cpu_start: cpu freq: 240000000
I (502) cpu_start: Application information:
I (507) cpu_start: Project name:     smoke-x
I (511) cpu_start: App version:      b4fe55c-dirty
I (517) cpu_start: Compile time:     Sep 12 2022 21:50:55
I (523) cpu_start: ELF file SHA256:  fb1543f39c8e3550...
I (529) cpu_start: ESP-IDF:          v4.4.2
I (534) heap_init: Initializing. RAM available for dynamic allocation:
I (541) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (547) heap_init: At 3FFBB958 len 000246A8 (145 KiB): DRAM
I (553) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (560) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (566) heap_init: At 40095A54 len 0000A5AC (41 KiB): IRAM
I (574) spi_flash: detected chip: winbond
I (577) spi_flash: flash io: dio
I (582) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (645) smoke_x: Device is paired to ****** at 905500000 MHz
I (775) app_lora: LoRa module initialized
I (775) smoke_x: Frequency set to: 905500000 MHz
I (775) app_lora: Starting LoRa Rx
I (785) wifi:wifi driver task: 3ffc5870, prio:23, stack:6656, core=0
I (785) system_api: Base MAC address is not set
I (785) system_api: read default base MAC address from EFUSE
I (795) wifi:wifi firmware version: eeaa27d
I (795) wifi:wifi certification version: v7.0
I (795) wifi:config NVS flash: enabled
I (805) wifi:config nano formating: disabled
I (805) wifi:Init data frame dynamic rx buffer num: 32
I (815) wifi:Init management frame dynamic rx buffer num: 32
I (815) wifi:Init management short buffer num: 32
I (825) wifi:Init dynamic tx buffer num: 32
I (825) wifi:Init static rx buffer size: 1600
I (825) wifi:Init static rx buffer num: 10
I (835) wifi:Init dynamic rx buffer num: 32
I (835) wifi_init: rx ba win: 6
I (845) wifi_init: tcpip mbox: 32
I (845) wifi_init: udp mbox: 6
I (845) wifi_init: tcp mbox: 6
I (855) wifi_init: tcp tx win: 5744
I (855) wifi_init: tcp rx win: 5744
I (865) wifi_init: tcp mss: 1440
I (865) wifi_init: WiFi IRAM OP enabled
I (865) wifi_init: WiFi RX IRAM OP enabled
I (875) wifi:Set ps type: 0

I (875) app_wifi: Wifi config SSID: ******
I (885) app_wifi: Wifi config password: ********************************
I (885) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (995) wifi:mode : sta (80:7d:3a:********)
I (995) wifi:enable tsf
I (1055) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (2545) wifi:state: init -> auth (b0)
I (2585) app_web_ui: Partition size: total: 956561, used: 268570
I (2585) app_web_ui: Starting HTTP Server
I (3545) wifi:state: auth -> init (200)
I (3545) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (4225) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (4225) wifi:state: init -> auth (b0)
I (4225) wifi:state: auth -> assoc (0)
I (4235) wifi:state: assoc -> run (10)
I (4255) wifi:connected with ******, aid = 14, channel 6, BW20, bssid = c8:03:f5:********
I (4255) wifi:security: WPA2-PSK, phy: bgn, rssi: -73
I (4255) wifi:pm start, type: 0

W (4265) wifi:<ba-add>idx:0 (ifx:0, c8:03:f5:********), tid:6, ssn:2, winSize:64
I (4325) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (5135) smoke_x_main: IP address obtained
I (5145) app_mqtt: Starting MQTT client
E (5145) MQTT_CLIENT: There are no transports valid, stop mqtt client, config scheme = mqtts
I (5145) esp_netif_handlers: sta ip: ***********, mask: *************, gw: *********
W (7455) wifi:<ba-add>idx:1 (ifx:0, c8:03:f5:********), tid:0, ssn:0, winSize:64
I (11405) app_lora: Packet received - Size: 70 RSSI: -50, SNR: 10.250000
I (11405) app_lora: ******,30,1,1,3,0,0,200,32,3,0,0,200,32,3,0,0,160,32,3,0,1,225,32,0,0,
I (11405) smoke_x: X4 DATA: ******,30,1,1,3,0,0,200,32,3,0,0,200,32,3,0,0,160,32,3,0,1,225,32,0,0,
G-Two commented 1 year ago

hmmm...it should work. I'm using MQTTS on mine with the same fields filled out. Do your MQTT broker logs show any helpful error messages?

fastbytes commented 1 year ago

Nothing at all, the device doesn't even appear to connect. If it works for you then must be something on my end. Will try to enable more debug logging and go from there.

G-Two commented 1 year ago

What version ESP-IDF are you using?

EDIT: never mind I can see in the logs 4.4.2

G-Two commented 1 year ago

Check your sdkconfig to ensure you have CONFIG_MQTT_TRANSPORT_SSL=y. I was able to replicate your error by turning this option off. You'll need to make clean after changing this option in order to ensure the MQTT library is rebuilt with TLS support.

fastbytes commented 1 year ago

Running make clean fixed it! Must have been missing after toggling it back/forth trying to get the initial link setup, but it's working great now.

Running ESP-IDF 4.4.2, connected successfully over MQTTS!

Closing issue -- we can chalk this one up to user error :)