Arduino MEGA - MQTT I/O device

Before I start, I am not a programmer, I dont do much of this at all but IoT is a passion and I’ve created some ALPHA code that was based on Jon’s LightSwitchMQTT controller.

The code has 24 digital inputs and 24 digital outputs. I’ve removed all of the original OLED and tempsensor code as its something I don’t need.

When the unit powers up it sends all of its input states out via MQTT so you can sync your automation device.

panelID = 20 , you can change in the code.

Inputs:
stat/20/Input/1 0 means the input is shorted to ground
stat/20/Input/1 1 means the input is open (pulled high)

Outputs:
cmnd/20/Output/1 0 means you’ve turned the output on (setup to go high to control chinese relay boards)
cmnd/20/Output/1 1 means you’ve turned the output off

In response to receiving an “output” command, the device will respond so you’ve got positive acknowledgement

Sending it a: cmnd/20/Output/1 0 will return stat/20/Output/1 0

This will work well with NodeRed (switch status as an input)

Unit will send: tele/20/Status Alive when the watchdog timer trips.

The code can be found at:

If anyone wants to help me clean it up or do things smarter and better you are welcome to do a pull. There is heaps of debug on the serial port, probably needs cleaning up but it all helps with debugging. There are some bugs in the code:

  1. Always reports A0 status on boot
  2. sscanf(topic,"%[^/]/%d/%[^/]/%d",&tempInt,&OutputNumber); doesnt parse correctly on the complete topic however it gives me integers ok.

Nice job!
Will have to take a look a time the code. What are you using for physical input devices?
And what boards are you using?

As the topic says, Arduino Mega 2560 with I/O breakout board from ALiexpress. I currently use 3 MEGA boards around the house for digital I/O ie: movement sensors, door switches and regular I/O control. These are the devices that form the access control and security for the house, as Jon has mentioned WIFI can be jammed with a multitude of devices hence why I went ethernet.

All the fancy lighting and PWM/Analoge control can be WIFI as if it stops working it doesnt compromise the house