Lemon2311 / IoTFleet.js

Library to control multiple microcontroller devices (ex: esp32, Rpi Pico) over-air with javascript :)
4 stars 1 forks source link
esp32 micropython rpi-pico-w

IoTFleet.js

Overview

The IoTFleet.js library is a versatile tool that enables control over multiple microcontroller devices like the Esp32 or Raspberry Pi Pico from a PC remotely using JavaScript.

Features

Software Requirements

How to use

First, download the project by pressing <>Code followed by Download Zip.

Download Zip

Extract the file (using a tool like WinRAR) and then:

To use the library a server needs to be run on the microcontroller device which can either be the EspServer.cpp or MicroPythonServer.py

EspServer.cpp

Suitable for Esp devices

Create a WiFiCredentials.h file inside Esp32Server.cpp/src containing your wifi credentials like so:

// WiFiCredentials.h
const char *ssid = "YOUR-WIFI-SSID";
const char *password = "YOUR-WIFI-PASSWORD";

Upload the main.cpp file located inside Esp32Server.cpp/src to the ESP32 using Platform.io and view the serial monitor. After the code has uploaded and the ESP32 connected to the WiFi, the IP address of the ESP32 will appear in the serial monitor. Copy it as you'll need it in a future step.

MicroPythonServer.py

Suitable for any device running MicroPython

Create a WIFI_CREDENTIALS.py file inside MicroPythonServer.py containing wifi credentials like so

# WIFI_CREDENTIALS.py
SSID = "SSID"
PASS = "PASS"

Save WIFI_CREDENTIALS.py, MicroAPIgRESTion.py to the MicroPython microcontroller device using Thonny IDE or any apropriate IDE.

Save MicroPythonServer.py as main.py on the MicroPython microcontroller device using Thonny IDE or any apropriate IDE.

Whatever main.py contains will be run at startup so now whenever the device powers up it will run the MicroPython server.

Then

Then using the library is easy. Copy the IoTFleet.js folder which contains the library and an example to your project and import the output and/or input function from script.js and use it like so:

//this example is taken from example.js

import { output, input } from "./IoTFleet.js"; //make sure to update your path as example.js is located
                                            //inside the same folder as IoTFleet.js

const { d13, a27 } = output("192.168.1.138", "d13", "a27");//declare and initialize output pins

d13.set("high");//set digital pin 13 to HIGH
a27.set(2);//set analog pin 27 to 2V

const { d3, a34 } = input("192.168.1.138", "d3", "a34");//declare and initialize input pins

await d3.get();//return digital pin 3 value
await a34.get();//return voltage of analog pin 34

Feature requests and contributions

I accept feature requests and contributions, so if you want a functionality that is not implemented already you can open an issue and if you want to contribute there are issues that need help and I`d be glad to guide you if you have any questions regarding them. Even more, is there a feature you want to add to this library and know how to implement it, open an issue about it and we can discuss details, then you can implement it and make a pull request.

Links:

Thank you me-no-dev for the EspAsyncWebServer library that was used to make the esp c++ async rest api: https://github.com/me-no-dev/ESPAsyncWebServer
Thanks to myself for the MicroAPIgRESTion library that was used to make the MicroPython async rest api: https://github.com/Lemon2311/MicroAPIgRESTion