DEV Community

Cover image for Remote invoke methods on your micro controller

Posted on • Updated on

Remote invoke methods on your micro controller

Few months ago I started to create a small device that will turn on/off the lights in my room, I needed this feature because in the evening I like to read, but turning off lights is a little bit painful because I have to stand up of my bed.

I've been started with ESP8266 controller because of incorporated Wifi and low price. First version of code used HTTP requests and executed actions based on GET calls (ex: put HIGH value on pin 13 was /action?pin=13&output=1 ), after first version I understood that controlling lights in other rooms will not be possible using the same code, project wasn't extendable in a easy way, I had to tune code for each room, adding additional parameter in request wasn't a good solution because I had to write source code on micro-controller customized for each device/room), also I had to remember IP addresses for calling actions.

Imagine a mobile application where you have to add IP addresses for each device you want to control and you have to handle situation when your IP addresses changes - it's not that easy and UX will be a bad one.

Knowing drawbacks and writing new requirements, my decision was to rewrite the project from scratch using MQTT as data transfer protocol.

After reading some articles about MQTT, I've decided to write code that will allow to control unlimited devices and as additional requirement I wanted to use the same code to control other things from my house ( like reading temperature from sensors or writing/reading from analog pins ) with easy and minimal setup, without editing the source code for each micro controller.

I started with idea that a small "core" should execute any methods that it knows about and they should be callable over MQTT. At this moment you can use MetalIO, add your methods in /src/functions and just register them in /src/main.cpp:

//create new instance
auto digitalWriteFunction = new DigitalWriteFunction("digitalWrite");
//register to metalio core
Enter fullscreen mode Exit fullscreen mode

Now you can call your method over MQTT as:
publish a message to your configured topic ( ex: /actions/room1 )

Enter fullscreen mode Exit fullscreen mode


One important thing is that MetalIO is fully configurable over Wifi, when you start device and click on BTN1 ( or any button that you can choose at compilation time, "TRIGGER_PIN" parameter in platformio.ini ), your device will create a named AP where you can connect and see config interface ( default address: )

At this moment MetalIO software can be written on any ESPx, Arduino or Intel Galileo Board, configured over Wifi and any application/dashboard that supports MQTT can be used to communicate with hardware devices.

Project can be found on GitHub:

Top comments (0)