"espFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.
Project description
OTAUpdateManager
espFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.
espFOTA
espFOTA is an Over-the-Air (OTA) update library for MicroPython devices such as ESP8266, ESP32, and other supported hardware. This library simplifies the process of updating firmware over a Wi-Fi connection, ensuring your devices are always up-to-date.
Table of Contents
Features
- Easy configuration for OTA updates.
- Automatic Wi-Fi connection management.
- Continuous update checks with automatic application of updates.
- Network status indicator using GPIO pin.
Installation
Installing with mip
Py-file
import mip
mip.install('github:raghulrajg/espFOTA/espFOTA.py')
To install using mpremote
mpremote mip install github:raghulrajg/espFOTA
To install directly using a WIFI capable board
mip.install("github:raghulrajg/espFOTA")
Installing Library Examples
If you want to install library examples:
mpremote mip install github:raghulrajg/espFOTA/examples.json
To install directly using a WIFI capable board
mip.install("github:raghulrajg/espFOTA/examples.json")
Installing from PyPI
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI <https://pypi.org/project/micropython-espFOTA/>
_.
To install for current user:
pip3 install micropython-espFOTA
To install system-wide (this may be required in some cases):
sudo pip3 install micropython-espFOTA
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install micropython-espFOTA
Also see examples.
Usage
Setup
-
Wi-Fi and Server Configuration:
SSID
: Your Wi-Fi network name.Password
: Your Wi-Fi network password.host
: The server endpoint where the update file is hosted.
-
Example Program:
Save the following code in a file named
main.py
on your MicroPython device:import espFOTA # Avoid the GPIO pin number 2 because of predefine pin (Network status indicator) # Server connection config host = "package.xyz.com/newversion" # WiFi Network connection config SSID = "YOUR_APN_NAME" Password = "YOUR_APN_PASSWORD" OTAUpdate = espFOTA.espFOTA(SSID, Password, host) def loop(): while True: # Put your code here OTAUpdate.run() if __name__ == '__main__': loop()
- SSID: Replace with your Wi-Fi network name.
- Password: Replace with your Wi-Fi network password.
- host: Replace with your server's URL endpoint where the OTA update file is hosted.
Network Status Indicator
- The device uses GPIO pin 2 as a network status indicator.
- If the Wi-Fi network is not connected, the LED on GPIO pin 2 will turn on.
- Once the Wi-Fi is connected, the LED will turn off.
Automatic Update Check
- The
OTAUpdate.run()
method continuously checks for updates from the specified host. - If an update is found, it is automatically downloaded and applied.
- The device will restart to apply the new firmware.
Example Node.js Server
To serve the OTA update file, you can set up a simple Node.js server. Here is an example:
const http = require('http');
const url1 = require('url');
const fs = require('fs');
const server1 = http.createServer((req, res) => {
const parsedUrl = url1.parse(req.url, true);
const pathname = parsedUrl.pathname;
if (pathname === '/download') {
const filePath = `filepath/ota.py`; // Path to your OTA update file
// Send the bin file to esp32
serveFile(res, filePath);
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not found');
}
});
function serveFile(res, filePath) {
const stat = fs.statSync(filePath);
const fileStream = fs.createReadStream(filePath);
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': stat.size,
'Content-Disposition': 'attachment; filename=' + "ota.py"
});
console.log(stat.size);
fileStream.pipe(res);
console.log("Downloaded");
fs.unlinkSync(filePath);
}
server1.listen(3000, () => {
console.log('Server listening on port 3000');
});
Server Setup:
- Save the above code in a file, e.g.,
server.js
. - Ensure you have Node.js installed.
- Run the server using the command: node
server.js
.
Endpoint:
- The server listens on port 3000. The OTA update file should be accessible at
http://<server-ip>:3000/download
.
Important Notes
- File Naming: The example program file name must be
main.py
on your MicroPython device. - Wi-Fi and Host Configuration: Ensure that the SSID, Password, and host variables are correctly set to match your network and server configurations.
- Update Check Frequency: The
OTAUpdate.run()
method continuously checks for updates. Adjust the frequency or conditions within the loop function as needed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file micropython-espFOTA-1.0.0.tar.gz
.
File metadata
- Download URL: micropython-espFOTA-1.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90dea466abede2ad4550038760b157c4dd691b41d56996a9288dcdb1a681700e |
|
MD5 | e1ce729cd6afac4a3900fdcd6c3662a0 |
|
BLAKE2b-256 | bb49edda7251b041e27bbcbb56cff1488c137dba324f5a3329c97009ad22c89f |
File details
Details for the file micropython_espFOTA-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: micropython_espFOTA-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c794a648d806c98e03fcc7fd362b91eb921240593402a24c4eebe968c15a129 |
|
MD5 | 4fe7bc314d42560b9da39c39cdd7fc00 |
|
BLAKE2b-256 | ca0d409ceece4ccebc71c207cbe20e47922230f19d4c2dd2685470d5037e0ae9 |