QingPing CGH1 & M5Stick-C

Hi - I bought a few of these sensors and I’m trying to get them to work with a M5Stick-C using 0.9.10.

I saw that you need to change two parameters when compiling to make sure it is responsive - I think they are.

#ifndef Scan_duration
#  define Scan_duration 1000 //define the time for a scan
#endif
#ifndef BLEScanInterval
#  define BLEScanInterval 52 // How often the scan occurs / switches channels; in milliseconds,
#endif

If I set BLEScanInterval to 1 I get a number of Nimble errors. If I leave it at 52, the Stick panics:

Using '/dev/cu.usbserial-85528FEF8B' as serial port.
Showing logs:
[09:22:24]*WM: [2] Portal Timeout In 99 seconds
[09:22:31]*WM: [3] -> captive.apple.com 
[09:22:31]*WM: [2] <- Request redirected to captive portal 
[09:22:31]*WM: [2] <- HTTP Root 
[09:22:31]*WM: [3] -> 192.168.4.1 
[09:22:31]*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
[09:22:31]*WM: [3] lastconxresult: WL_DISCONNECTED
[09:22:31]*WM: [2] WiFi Scan ASYNC started 
[09:22:36]*WM: [2] WiFi Scan ASYNC completed in 5315 ms
[09:22:36]*WM: [2] WiFi Scan ASYNC found: 38
[09:22:41]*WM: [3] -> captive.apple.com 
[09:22:41]*WM: [2] <- Request redirected to captive portal 
[09:22:42]*WM: [2] <- HTTP Root 
[09:22:42]*WM: [3] -> 192.168.4.1 
[09:22:42]*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
[09:22:42]*WM: [3] lastconxresult: WL_DISCONNECTED
[09:22:42]*WM: [2] Scan is cached 5656 ms ago
[09:22:42]*WM: [3] -> captive.apple.com 
[09:22:42]*WM: [2] <- Request redirected to captive portal 
[09:22:42]*WM: [2] <- HTTP Root 
[09:22:42]*WM: [3] -> 192.168.4.1 
[09:22:42]*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
[09:22:42]*WM: [3] lastconxresult: WL_DISCONNECTED
[09:22:42]*WM: [2] Scan is cached 5733 ms ago
[09:22:43]*WM: [2] <- HTTP Wifi 
[09:22:43]*WM: [2] Scan is cached 7044 ms ago
[09:22:43]*WM: [1] 38 networks found
*** many APs shown
[09:22:43]*WM: [2] AP:  -84 DIRECT-CB-HP ENVY Pro 6400
[09:22:43]*WM: [2] AP:  -84 DIRECT-44-HP OfficeJet Pro 6960
***
[09:22:43]*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
[09:22:43]*WM: [3] lastconxresult: WL_DISCONNECTED
[09:22:43]*WM: [3] Sent config page 
[09:22:43]*WM: [3] -> captive.apple.com 
[09:22:43]*WM: [2] <- Request redirected to captive portal 
[09:22:43]*WM: [2] <- HTTP Root 
[09:22:43]*WM: [3] -> 192.168.4.1 
[09:22:43]*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
[09:22:43]*WM: [3] lastconxresult: WL_DISCONNECTED
[09:22:43]*WM: [2] Scan is cached 7232 ms ago
[09:22:54]*WM: [2] Portal Timeout In 109 seconds
[09:23:00]*WM: [2] <- HTTP WiFi save  
[09:23:00]*WM: [3] Method: POST
[09:23:00]*WM: [2] Parameters 
[09:23:00]*WM: [2] -------------------- 
[09:23:00]*WM: [2] server: 192.168.0.215
[09:23:00]*WM: [2] port: 1883
[09:23:00]*WM: [2] user: your_username
[09:23:00]*WM: [2] pass: your_password
[09:23:00]*WM: [2] secure: 
[09:23:00]*WM: [2] cert: 
[09:23:00]*WM: [2] name: OMG_M5STICK_2
[09:23:00]*WM: [2] topic: home/
[09:23:00]*WM: [2] -------------------- 
[09:23:00]*WM: [3] Sent wifi save page 
[09:23:00]*WM: [2] process connect 
[09:23:02]*WM: [2] Connecting as wifi client... 
[09:23:02]*WM: [1] STA static IP:
[09:23:02]*WM: [2] setSTAConfig static ip not set 
[09:23:02]*WM: [3] WIFI station disconnect 
[09:23:02]*WM: [1] Connecting to new AP: xxxx
[09:23:02]*WM: [3] Using Password: xxxx
[09:23:02]*WM: [3] WiFi station enable 
[09:23:02]*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
[09:23:08]*WM: [2] Connection result: WL_CONNECTED
[09:23:08]*WM: [3] lastconxresult: WL_CONNECTED
[09:23:08]*WM: [1] Connect to new AP [SUCCESS] 
[09:23:08]*WM: [1] Got IP Address: 
[09:23:08]*WM: [1] 192.168.99.162 
[09:23:08]*WM: [3] -> captive.apple.com 
[09:23:08]*WM: [2] <- Request redirected to captive portal 
[09:23:08]*WM: [2] disconnect configportal 
[09:23:08]*WM: [0] [ERROR] disconnect configportal - softAPdisconnect FAILED 
[09:23:09]*WM: [2] restoring usermode STA
[09:23:09]*WM: [2] wifi status: WL_CONNECTED
[09:23:09]*WM: [2] wifi mode: STA
[09:23:09]*WM: [1] config portal exiting 
[09:23:11]{
[09:23:11]  "mqtt_server": "192.168.0.215",
[09:23:11]  "mqtt_port": "1883",
[09:23:11]  "mqtt_user": "your_username",
[09:23:11]  "mqtt_pass": "your_password",
[09:23:11]  "mqtt_topic": "home/",
[09:23:11]  "gateway_name": "OMG_M5STICK_2",
[09:23:11]  "mqtt_broker_secure": false,
[09:23:11]  "mqtt_broker_cert": "",
[09:23:11]  "mqtt_ss_index": 0,
[09:23:11]  "ota_server_cert": ""
[09:23:15]}Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
[09:23:15]Core 1 register dump:
[09:23:15]PC      : 0x4000127a  PS      : 0x00060730  A0      : 0x800d8db6  A1      : 0x3ffcdc30  
[09:23:15]A2      : 0x3f4015be  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x0000ff00  
[09:23:15]A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000057  A9      : 0x00000064  
[09:23:15]A10     : 0x00000003  A11     : 0x3ffcdd90  A12     : 0x3ffcdd68  A13     : 0x3ffe3ad6  
[09:23:15]A14     : 0x00000000  A15     : 0x0000007d  SAR     : 0x00000010  EXCCAUSE: 0x0000001c  
[09:23:15]EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  
[09:23:15]
[09:23:15]ELF file SHA256: 0000000000000000
[09:23:15]
[09:23:15]Backtrace: 0x4000127a:0x3ffcdc30 0x400d8db3:0x3ffcdc40 0x400d9e86:0x3ffce3e0 0x400e1209:0x3ffce920 0x40117640:0x3ffce940 0x40091b66:0x3ffce960
[09:23:15]
[09:23:15]Rebooting...
[09:23:15]ets Jun  8 2016 00:22:57
[09:23:15]
[09:23:15]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[09:23:15]configsip: 188777542, SPIWP:0xee
[09:23:15]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[09:23:15]mode:DIO, clock div:2
[09:23:15]load:0x3fff0018,len:4
[09:23:15]load:0x3fff001c,len:1044
[09:23:15]load:0x40078000,len:10124
[09:23:15]load:0x40080400,len:5828
[09:23:15]entry 0x400806a8
[09:23:16]N: 
[09:23:17]**********[09:23:18]{
[09:23:18]  "mqtt_server": "192.168.0.215",
[09:23:18]  "mqtt_port": "1883",
[09:23:18]  "mqtt_user": "your_username",
[09:23:18]  "mqtt_pass": "your_password",
[09:23:18]  "mqtt_topic": "home/",
[09:23:18]  "gateway_name": "OMG_M5STICK_2",
[09:23:18]  "mqtt_broker_secure": false,
[09:23:18]  "mqtt_broker_cert": "",
[09:23:18]  "mqtt_ss_index": 0,
[09:23:18]  "ota_server_cert": ""
[09:23:18]}*WM: [1] Free heap:        148924
[09:23:18]*WM: [1] ESP-IDF version:  v3.3.5-1-g85c43024c
[09:23:18]*WM: [3] allocating params bytes: 20
[09:23:18]*WM: [2] Added Parameter: server
[09:23:18]*WM: [2] Added Parameter: port
[09:23:18]*WM: [2] Added Parameter: user
[09:23:18]*WM: [2] Added Parameter: pass
[09:23:18]*WM: [2] Added Parameter: secure
[09:23:18]*WM: [3] Updated _max_params: 10
[09:23:18]*WM: [3] re-allocating params bytes: 40
[09:23:18]*WM: [2] Added Parameter: cert
[09:23:18]*WM: [2] Added Parameter: name
[09:23:18]*WM: [2] Added Parameter: topic
[09:23:18]E (4561) wifi:sta is connecting, return error
[09:23:19]E (5063) wifi:sta is connecting, return error
[09:23:19]E (5564) wifi:sta is connecting, return error
[09:23:20]E (6065) wifi:sta is connecting, return error
[09:23:22]*WM: [1] AutoConnect 
[09:23:22]*WM: [2] ESP32 event handler enabled 
[09:23:22]*WM: [1] AutoConnect: ESP Already Connected 
[09:23:22]*WM: [1] STA static IP:
[09:23:22]*WM: [2] setSTAConfig static ip not set 
[09:23:22]*WM: [1] AutoConnect: SUCCESS 
[09:23:22]*WM: [1] STA IP Address: 192.168.6.162
[09:24:25]Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
[09:24:25]Core 1 register dump:
[09:24:25]PC      : 0x4000127a  PS      : 0x00060330  A0      : 0x800d8db6  A1      : 0x3ffcdeb0  
[09:24:25]A2      : 0x3f4015be  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x0000ff00  
[09:24:25]A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000057  A9      : 0x00000064  
[09:24:25]A10     : 0x00000003  A11     : 0x3ffce010  A12     : 0x3ffcdfe8  A13     : 0x3ffe7fda  
[09:24:25]A14     : 0x00000000  A15     : 0x0000007d  SAR     : 0x00000010  EXCCAUSE: 0x0000001c  
[09:24:25]EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  
[09:24:25]
[09:24:25]ELF file SHA256: 0000000000000000
[09:24:25]
[09:24:25]Backtrace: 0x4000127a:0x3ffcdeb0 0x400d8db3:0x3ffcdec0 0x400d9e86:0x3ffce660 0x400e1209:0x3ffceba0 0x40117640:0x3ffcebc0 0x40091b66:0x3ffcebe0
[09:24:25]
[09:24:25]Rebooting...
[09:24:25]ets Jun  8 2016 00:22:57
[09:24:25]
[09:24:25]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[09:24:25]configsip: 188777542, SPIWP:0xee
[09:24:25]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[09:24:25]mode:DIO, clock div:2
[09:24:25]load:0x3fff0018,len:4
[09:24:25]load:0x3fff001c,len:1044
[09:24:25]load:0x40078000,len:10124
[09:24:25]load:0x40080400,len:5828
[09:24:25]entry 0x400806a8
[09:24:26]N: 
[09:24:27]************* [09:24:28]{
[09:24:28]  "mqtt_server": "192.168.0.215",
[09:24:28]  "mqtt_port": "1883",
[09:24:28]  "mqtt_user": "your_username",
[09:24:28]  "mqtt_pass": "your_password",
[09:24:28]  "mqtt_topic": "home/",
[09:24:28]  "gateway_name": "OMG_M5STICK_2",
[09:24:28]  "mqtt_broker_secure": false,
[09:24:28]  "mqtt_broker_cert": "",
[09:24:28]  "mqtt_ss_index": 0,
[09:24:28]  "ota_server_cert": ""
[09:24:28]}*WM: [1] Free heap:        148924
[09:24:28]*WM: [1] ESP-IDF version:  v3.3.5-1-g85c43024c
[09:24:28]*WM: [3] allocating params bytes: 20
[09:24:28]*WM: [2] Added Parameter: server
[09:24:28]*WM: [2] Added Parameter: port
[09:24:28]*WM: [2] Added Parameter: user
[09:24:28]*WM: [2] Added Parameter: pass
[09:24:28]*WM: [2] Added Parameter: secure
[09:24:28]*WM: [3] Updated _max_params: 10
[09:24:28]*WM: [3] re-allocating params bytes: 40
[09:24:28]*WM: [2] Added Parameter: cert
[09:24:28]*WM: [2] Added Parameter: name
[09:24:28]*WM: [2] Added Parameter: topic
[09:24:28]E (4530) wifi:sta is connecting, return error
[09:24:29]E (5032) wifi:sta is connecting, return error
[09:24:29]E (5533) wifi:sta is connecting, return error
[09:24:30]E (6034) wifi:sta is connecting, return error
[09:24:32]*WM: [1] AutoConnect 
[09:24:32]*WM: [2] ESP32 event handler enabled 
[09:24:32]*WM: [1] AutoConnect: ESP Already Connected 
[09:24:32]*WM: [1] STA static IP:
[09:24:32]*WM: [2] setSTAConfig static ip not set 
[09:24:32]*WM: [1] AutoConnect: SUCCESS 
[09:24:32]*WM: [1] STA IP Address: 192.168.6.162

Any thoughts? Is there a pre-compiled binary somewhere I could grab that would work?

Hi alfista2600,

have you tried setting TimeBtwRead to 0, instead of the BLEScanInterval which I would leave as is, or try the precompiled/ready configured esp32dev-ble-cont environment in platformio.ini.

I think you might have mixed up the TimeBtwRead and BLEScanInterval parameters :wink:

Hope this helps

1 Like

Thanks @DigiH - I’ll give this a try. I did feel like I maybe had the settings wrong…

Thanks again, and esp32dev-ble-cont installed via Chrome works just fine from the bluetooth perspective, but unfortunately it doesn’t retain wifi settings for some reason, and I can’t re-enter them either.

I wipe the device first with M5Burner. Then do the install. However after I power cycle to move it, it goes back into AP mode. When I connect to the AP again, it shows that it saved the MQTT host and device name, but it forgot the Wifi settings… and won’t save them if I enter them again.

Hmm, not sure what might be the problem there, someone else might know if there is an issue with that. I only ever used the WiFi MQTT entering mode the first time I discovered OMG. Since then I hard code them when doing the builds in platformio.

Since you have previously compiled with platformio maybe try the same with extending the esp32dev-ble-cont environment.

Original in platformio.ini

[env:esp32dev-ble-cont]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE_C"'
  '-DTimeBtwRead=0'
  '-DScan_duration=1000'
  '-DAttemptBLECOnnect=false'

extend it like this

[env:esp32dev-ble-cont]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE_C"'
  '-DTimeBtwRead=0'
  '-DScan_duration=1000'
  '-DAttemptBLECOnnect=false'
  '-DESPWifiManualSetup=true'
  '-Dwifi_ssid="NETWORKNAME"'
  '-Dwifi_password="NETWORKPASSWORD"'
  '-DMQTT_SERVER="192.168.x.x"'
  '-DMQTT_USER="your_username"'
  '-DMQTT_PASS="your_password"'
  '-DMQTT_PORT "8883"/""1883""'

MQTT_USER, MQTT_PASS and port 8883 if your MQTT broker requires secure connections, otherwise port 1883 and no username and password.

All the best.

P.S.: Looking through platform.ini I find that the esp32-m5stick-c-ble environment has some extra lib_deps and build_flags

lib_deps =

${libraries.m5stickc}

build_flags =

‘-DZboardM5STICKC=“M5StickC”’

so adding these to the virgin esp32dev-ble-cont or adding

  '-DTimeBtwRead=0'
  '-DScan_duration=1000'
  '-DAttemptBLECOnnect=false'

to esp32-m5stick-c-ble environment might actually not need the hard coded WiFi and MQTT details.

Would be good if you let us know what you end up with :slight_smile:

Thanks - yes, I pieced together your instructions and got it working properly, adding the additional parameters to the esp32-m5stick-c-ble section.

I am barely beyond a beginner using these tools so find the more I touch the less likely it is to work, which is why I avoided adding all the wifi stuff. Turns out that I needed to escape a character in my wifi password that I didn’t think I’d need to, which gave compilation errors in a section I didn’t think was related.

Appreciate the help!