A platform-independent connectivity library to build IoT projects that work across different hardware with minimal code changes.
The MDevice library eliminates the headache of managing different WiFi implementations across Arduino, ESP32, and STM32 boards. Write your code once and deploy it to any supported platform without changing your core application logic.
- Cross-platform compatibility - Works seamlessly on Arduino (with WiFi support), ESP32, and STM32 boards
- Automatic platform detection - No need to modify your code when switching hardware
- Simple API - Common interface for all your connectivity needs
- Command handling - Receive and process commands from a remote server
- JSON support - Send structured data with minimum effort
- Open the Arduino IDE
- Go to Sketch → Include Library → Manage Libraries...
- Search for "MDevice"
- Look for "MDevice by MEmbedded TechLab"
- Click Install
- Download the latest release as ZIP
- In Arduino IDE: Sketch → Include Library → Add .ZIP Library...
- Select the downloaded ZIP file
This library requires:
- ArduinoJson (6.0.0+)
- WiFiNINA (for Arduino boards with WiFi)
- ArduinoHttpClient (for STM32 boards)
These will be automatically installed if you use the Arduino Library Manager.
#include <MDevice.h>
// The Device type is automatically selected based on your platform
Device myDevice("device123");
void setup() {
Serial.begin(115200);
// Initialize the device
myDevice.initialize();
// Connect to WiFi
if(myDevice.connectWiFi("your_ssid", "your_password")) {
Serial.println("Connected to WiFi!");
// Register device with server
if(myDevice.sendDeviceConnect()) {
Serial.println("Device registered!");
}
}
}
void loop() {
// Check for incoming commands
myDevice.checkForCommands();
// Process any pending commands
auto& commands = myDevice.getPendingCommands();
for(auto& cmd : commands) {
Serial.print("Received command: ");
Serial.print(cmd.name);
Serial.print(" with status: ");
Serial.println(cmd.status);
// Process command here...
}
commands.clear(); // Clear processed commands
// Send some data to the server
myDevice.sendData("sensor", "temp_sensor", "temperature", 25);
delay(5000); // Wait 5 seconds before next update
}
The library uses conditional compilation to select the appropriate implementation:
- Arduino boards with WiFi support (Nano 33 IoT, MKR WiFi 1010, etc.) - Uses WiFiNINA library
- ESP32 boards - Uses the native ESP32 WiFi and HTTP libraries
- STM32 boards - Uses ArduinoHttpClient with WiFi support
Commands received from the server follow this structure:
struct Command {
String name; // Name of the command
int status; // Status or value associated with the command
};
The library provides multiple ways to send data:
// Send numeric data
myDevice.sendData("sensor", "temp_sensor", "temperature", 25);
// Send string data
myDevice.sendData("status", "system", "message", "all systems normal");
// Send complex data with array
JsonArray dataArray = doc.createNestedArray("readings");
dataArray.add(25);
dataArray.add(26);
dataArray.add(24);
myDevice.sendData("sensor", "temp_sensor", "temperature_history", 3, dataArray);
Developed by MEmbedded TechLab