Github Boards Devices Community Docs Blog

M5Stack first installation of OMG, how to?

Hello all!
I am completely new to OMG, but not new to smart home automation and have worked with HASS and MQTT before.

I have a brand new M5Stack Core basic and after looking around in the docs, Github and here, but I have not found a description how to easily put OMG on M5Stack Basic. I am not saying that there is no such description, I am just saying I did not find it. I am not complaining, I just would be happy to get pointers to the right documents and articles.

I do not have any IDE installed, also nothing for Arduino.

What is the easiest way do go? Do I need to flash it vie USB serial or could I just put an image on the SD card?

Also articles on integration OMG on M5Stack into HASS would be helpful, maybe there are some useful templates? Or does it support auto discovery?

All help appreciated!
Keep happy and safe!

Hello,

The easiest way is to flash the pre built binaries to the M5Stack by following this tutorial (USB):
https://docs.openmqttgateway.com/upload/binaries.html

Also articles on integration OMG on M5Stack into HASS would be helpful, maybe there are some useful templates? Or does it support auto discovery?

It supports auto discovery by default for BLE devices and the gateway itself, so the devices qnd the gateway are automatically created (when seen for the first time) into Configuration->Devices with the corresponding entities, here is a gif of v0.9.6beta

Oh, yeah, I saw that description and it doesn’t work for me as I have no windows machine at all, not even a VM. Is there no way to do it on real operating system :slight_smile: ?

Can it be done using the Arduino IDE? I installed that.

You can use ESPTOOL instead of ESP32 download tool:

Follow the first part of the tutorial below (until Download the boot_app0 from here):
https://docs.openmqttgateway.com/upload/binaries.html

And instead of using ESP32 download tool, install and use ESPTOOL.

esptool.py erase_flash
esptool.py --port COM4 write_flash 0xe000 boot_app0.bin 0x1000 bootloader_dio_80m.bin 0x10000 esp32-m5stick-ble-firmware.bin 0x8000 esp32-m5stack-ble-partitions.bin

You may find the right --port by checking the Arduino IDE Tools->Port

Of course, see below:
https://docs.openmqttgateway.com/upload/arduino-ide.html

Here is the configuration for M5Stack core 1 and arduino IDE:

#define ZgatewayBT     "BT"       //ESP8266, ESP32
#define ZsensorGPIOInput "GPIOInput" //ESP8266, Arduino, ESP32
#define ZmqttDiscovery "HADiscovery"//ESP8266, Arduino, ESP32, Sonoff RF Bridge
#define ZboardM5STACK  "ZboardM5STACK"

LED_RECEIVE=15
TRIGGER_GPIO=37
SLEEP_BUTTON=38
DINPUT_GPIO=39

Thanks I will give it a shot!

I followed this description:
https://docs.openmqttgateway.com/upload/arduino-ide.html

Using

LED_RECEIVE=15
TRIGGER_GPIO=37
SLEEP_BUTTON=38
DINPUT_GPIO=39

I get:

Arduino: 1.8.13 (Mac OS X), Board: "M5Stack-Core-ESP32, QIO, 80MHz, Minimal SPIFFS (Large APPS with OTA), 921600, None"











In file included from /Users/uli/Downloads/OpenMQTTGateway-0.9.5/main/main.ino:28:0:
User_config.h:211:1: error: 'LED_RECEIVE' does not name a type
 LED_RECEIVE=15
 ^
/Users/uli/Downloads/OpenMQTTGateway-0.9.5/main/main.ino: In function 'void loop()':
main:1195:18: error: 'timer_sys_measures' was not declared in this scope
       if (now > (timer_sys_measures + (TimeBetweenReadingSYS * 1000)) || !timer_sys_measures) {
                  ^
Multiple libraries were found for "FreeRTOS.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/BLE
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino
Multiple libraries were found for "WiFi.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/WiFi
Multiple libraries were found for "SD.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SD
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/SD
exit status 1
'LED_RECEIVE' does not name a type


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Using

#define LED_RECEIVE 15
#define TRIGGER_GPIO 37
#define SLEEP_BUTTON 38
#define DINPUT_GPIO 39

I get:

Arduino: 1.8.13 (Mac OS X), Board: "M5Stack-Core-ESP32, QIO, 80MHz, Minimal SPIFFS (Large APPS with OTA), 921600, None"











In file included from /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.cpp:8:0:
/Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.h:72:31: error: 'RingbufferType_t' has not been declared
     Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT);
                               ^
/Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.cpp:268:39: error: 'RingbufferType_t' has not been declared
 Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type) {
                                       ^
/Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.cpp: In constructor 'Ringbuffer::Ringbuffer(size_t, int)':
/Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.cpp:272:48: error: invalid conversion from 'int' to 'ringbuf_type_t' [-fpermissive]
     m_handle = ::xRingbufferCreate(length, type);
                                                ^
In file included from /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.h:14:0,
                 from /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino/src/FreeRTOS.cpp:8:
/Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/include/esp_ringbuf/freertos/ringbuf.h:69:17: note:   initializing argument 2 of 'void* xRingbufferCreate(size_t, ringbuf_type_t)'
 RingbufHandle_t xRingbufferCreate(size_t xBufferSize, ringbuf_type_t xBufferType);
                 ^
Multiple libraries were found for "SD.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SD
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/SD
Multiple libraries were found for "WiFi.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/WiFi
Multiple libraries were found for "FreeRTOS.h"
 Used: /Users/uli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/BLE
 Not used: /Applications/ExternalApplications/Hardware/Arduino/Arduino.app/Contents/Java/libraries/NimBLE-Arduino
exit status 1
Error compiling for board M5Stack-Core-ESP32.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Did you took the libraries below:
https://github.com/1technophile/OpenMQTTGateway/releases/download/v0.9.6beta/esp32-m5stack-ble-libraries.zip

yes I put them to the other libraries

Could you indicate the version of Arduino ESP32 used?
Should be 1.0.6

Working here:

image

I have 1.0.6 installed

Could you show the part of the config file where you have the values for LED_RECEIVE etc?

In the meanwhile I used esptool.py to install the firmware. I would better like to use Arduino IDE, and if we can get it to work it would be good.

The M5 stack is discovered into HASS but it discovers a lot less attributes than described in the docs.

Also I set it to lowpowermode 2 by mistake by pressing the middle button. Trying to set it to lowpowermode 1 via MQTT does not work. I used this topic and message:

myroom/myomgdevicename/commands/MQTTtoBT/config
{"lowpowermode":1}

You need to publish a message with retain flag, this way when the gateway connects after the deep sleep it retrieves the instruction.
The other option is to erase the flash and upload again.

The M5Stack specific parameters are not auto discovered indeed, even if they are published.
Are you referring to battery data?

The error you have is likely due to a wrong library version of NimBLE arduino, on the screenshot you can see the different libraries versions used and compare them with your build trace.

I compared in HASS the discovered attributes with the picture here:
https://docs.openmqttgateway.com/integrate/home_assistant.html#auto-discovery

I just get:

disc

I have it compiling fine now, it was indeed the Nimble library. There is obviously an outdated version in the 0.9.5. library package for m5stack (esp32-m5stack-ble-libraries.zip), but I could update it in the library manager.

I published the lowpowermode with retain now, it does not work. Even after flashing the M5stack with Arduino IDE and long pressing Button C for erasure it is still in low power mode 2, which is highly unfortunate.

Your best guess is to erase the flash esptool.py erase_flash and upload.

I will see if I can reproduce

Not really an outdated version, just a version fitting with the ESP32 arduino framework previous version.

If you push the lateral button (red one) one time and after the middle button several times you can go back to low power mode 0.