A powerful and easy-to-use library that seamlessly integrates your ESP8266/ESP32 IoT devices into the Firmngin Platform, enabling real-time device management, remote control, and secure payment processing capabilities. Built with secure communication, this library provides a simple event-driven API that handles all the complexity of device connectivity, allowing you to focus on building amazing IoT applications π°.
Visit firmngin.dev for more information and try it for free.
- ESP8266 and ESP32 support
- Event-driven callback system
- Simple state-based API
-
Install required libraries via Library Manager:
- ArduinoJson
- PubSubClient
-
Download this library and place it in Arduino IDE
librariesfolder -
Download
keys.hand put it in your sketch folder with main sketch files:
// keys.h
static const char CA_CERT[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
[Your CA Certificate]
-----END CERTIFICATE-----
)EOF";
static const char CLIENT_CERT[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
[Your Client Certificate]
-----END CERTIFICATE-----
)EOF";
static const char PRIVATE_KEY[] PROGMEM = R"EOF(
-----BEGIN PRIVATE KEY-----
[Your Private Key]
-----END PRIVATE KEY-----
)EOF";
static const uint8_t SERVER_FINGERPRINT_BYTES[20] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};#include "keys.h" // Your certificate file
#include "firmnginKit.h"
#include <ArduinoJson.h>
#define DEVICE_ID "YOUR_DEVICE_ID"
#define DEVICE_KEY "YOUR_DEVICE_KEY"
// ESP8266
FirmnginKit fngin(DEVICE_ID, DEVICE_KEY, CLIENT_CERT, PRIVATE_KEY, SERVER_FINGERPRINT_BYTES);
// ESP32
// FirmnginKit fngin(DEVICE_ID, DEVICE_KEY, CA_CERT, CLIENT_CERT, PRIVATE_KEY);
void setup() {
Serial.begin(115200);
// Connect WiFi first
WiFi.begin("SSID", "PASSWORD");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Setup handler for any event
fngin.onState(PAYMENT_SUCCESS, [](DeviceState state) {
String payload = state.getPayload();
Serial.println("Payment received!");
Serial.println(payload);
// Parse JSON with ArduinoJson
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
if (doc.containsKey("amount")) {
int amount = doc["amount"];
Serial.print("Amount: ");
Serial.println(amount);
}
});
fngin.onState(DEVICE_STATUS, [](DeviceState state) {
Serial.println("Device status requested");
Serial.println(state.getPayload());
});
fngin.onState(PAYMENT_PENDING, [](DeviceState state) {
Serial.println("Payment pending");
Serial.println(state.getPayload());
});
fngin.onState(CUSTOM_ON_PENDING_PAYMENTS, [](DeviceState state) {
Serial.println("On pending payments");
Serial.println(state.getPayload());
});
fngin.onState(CUSTOM_ON_EXPIRED_PAYMENTS, [](DeviceState state) {
Serial.println("On expired payments");
Serial.println(state.getPayload());
});
fngin.onState(CUSTOM_ON_SUCCESS_PAYMENTS, [](DeviceState state) {
Serial.println("On success payments");
Serial.println(state.getPayload());
});
fngin.setDebug(false); // Enable debug output
fngin.setTimezone(7); // Set timezone (GMT+7 for Indonesia)
fngin.begin();
}
void loop() {
fngin.loop(); // Must be called continuously
}// ESP8266
FirmnginKit fngin(deviceId, deviceKey, clientCert, privateKey, fingerprint);
// ESP32
FirmnginKit fngin(deviceId, deviceKey, caCert, clientCert, privateKey);fngin.begin()- Start connection to server (call after WiFi connected)fngin.loop()- Must be called continuously inloop()
fngin.onState(PAYMENT_SUCCESS, callback)- Handler for payment successfngin.onState(DEVICE_STATUS, callback)- Handler for device status requestfngin.onState(PAYMENT_PENDING, callback)- Handler for payment pendingfngin.onState(CUSTOM_ON_PENDING_PAYMENTS, callback)- Handler for pending paymentsfngin.onState(CUSTOM_ON_EXPIRED_PAYMENTS, callback)- Handler for expired paymentsfngin.onState(CUSTOM_ON_SUCCESS_PAYMENTS, callback)- Handler for success payments
fngin.setDebug(true/false)- Enable/disable debug outputfngin.setTimezone(7)- Set timezone (default: +7 for Indonesia)fngin.setNtpServer("pool.ntp.org")- Set NTP serverfngin.setMQTTServer("server.com", 8883)- Set custom MQTT server
The library provides easy-to-read enums:
| Enum | Description |
|---|---|
PAYMENT_SUCCESS |
Payment successfully received |
DEVICE_STATUS |
Device status request |
PAYMENT_PENDING |
Payment is pending |
CUSTOM_ON_PENDING_PAYMENTS |
Your data when pending payments event |
CUSTOM_ON_EXPIRED_PAYMENTS |
Your data when expired payments event |
CUSTOM_ON_SUCCESS_PAYMENTS |
Your data when success payments event |
All data is returned as JSON string. Use ArduinoJson for parsing:
fngin.onState(PAYMENT_SUCCESS, [](DeviceState state) {
String payload = state.getPayload();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
// Access fields
String refId = doc["reference_id"];
int amount = doc["amount"];
int sessionId = doc["active_session_id"];
});- Ensure WiFi is connected before calling
begin() - Ensure
keys.hfile exists in sketch folder with valid certificates - Enable debug mode to see detailed logs:
fngin.setDebug(true) - Restart device if connection issues occur
- Check Serial Monitor to see error messages
See examples/BasicExample/ folder for complete library usage example.
MIT License
Visit firmngin.dev for complete documentation and support.