Swagbadge2021 MQTT

From Open Hardware Miniconf
Revision as of 20:26, 15 January 2021 by Marcmerlin (talk | contribs) (Making your badge perform)
Jump to: navigation, search

Controlling your badge over MQTT

About the LCA Swagbadge MQTT server

The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it's faster.

This server is at 101.181.46.180, the configuration for which is held on the badge at configuration/mqtt.py. The server has some special features:

  • The upgrade/ topic path prefix is public read: only Jon and Andy can update it.
  • The aiko/ topic path prefix is public read/write
  • We have some server monitoring to look for things snooping for all the channels, or who aren't using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.

You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.

Making your badge perform

The easiest thing to do is send messages to show up on your screens.

  1. Install an mqtt client on your machine
  2. Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)
  3. Using your badge's topic (public/esp32_your_badge_id/0/in) send it a message

Messages are usually in the form of (component:command arguments).

mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0 & << does this receive anything?

mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m "(oled:clear)"

mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m "(oled:pixel 64 32)"

mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m "(oled:text 0 50 Hello World)"

OLED messages

(oled:clear)
clears both screens
(oled:log Hello World!)
writes a message along the bottom of the screens, scrolling up whatever is there out of the way
(oled:pixel x y)
lights a pixel at that spot
(oled:text x y This is a test !)
Puts some text at the position x,y. It will be displayed over the top of whatever's there.

If you'd like to make your application MQTT aware, take a look at the oled code.