micropython-espFOTA


Namemicropython-espFOTA JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
Summary"espFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.
upload_time2024-06-15 03:55:55
maintainerNone
docs_urlNone
authorRaghul Raj G
requires_pythonNone
licenseNone
keywords ota fota update microcontroller micropython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OTAUpdateManager
espFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.

[![micropython](https://img.shields.io/badge/micropython-Ok-purple.svg)](https://micropython.org)

[![ESP8266](https://img.shields.io/badge/ESP-8266-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp8266)

[![ESP32](https://img.shields.io/badge/ESP-32-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32)
[![ESP32](https://img.shields.io/badge/ESP-32S2-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32-s2)
[![ESP32](https://img.shields.io/badge/ESP-32C3-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32-c3)


# 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](#features)
- [Installation](#installation)
- [Usage](#usage)
  - [Setup](#setup)
  - [Network Status Indicator](#network-status-indicator)
  - [Automatic Update Check](#automatic-update-check)
- [Example Node.js Server](#example-nodejs-server)
- [Important Notes](#important-notes)

## 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
```python
import mip
mip.install('github:raghulrajg/espFOTA/espFOTA.py')
```

To install using mpremote

```bash
    mpremote mip install github:raghulrajg/espFOTA
```

To install directly using a WIFI capable board

```bash
    mip.install("github:raghulrajg/espFOTA")
```

### Installing Library Examples

If you want to install library examples:

```bash
    mpremote mip install github:raghulrajg/espFOTA/examples.json
```

To install directly using a WIFI capable board

```bash
    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:

```bash
    pip3 install micropython-espFOTA
```

To install system-wide (this may be required in some cases):


```bash
sudo pip3 install micropython-espFOTA
```
To install in a virtual environment in your current project:

```bash
    mkdir project-name && cd project-name
    python3 -m venv .venv
    source .env/bin/activate
    pip3 install micropython-espFOTA
```

Also see [examples](https://github.com/raghulrajg/espFOTA/tree/main/test).

## Usage

### Setup

1. **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.

2. **Example Program:**

    Save the following code in a file named `main.py` on your MicroPython device:

    ```python
    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:

```javascript
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.




            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "micropython-espFOTA",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "OTA, FOTA, Update, Microcontroller, Micropython",
    "author": "Raghul Raj G",
    "author_email": "raghulrajatmega328@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bb/49/edda7251b041e27bbcbb56cff1488c137dba324f5a3329c97009ad22c89f/micropython-espFOTA-1.0.0.tar.gz",
    "platform": null,
    "description": "# OTAUpdateManager\r\nespFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.\r\n\r\n[![micropython](https://img.shields.io/badge/micropython-Ok-purple.svg)](https://micropython.org)\r\n\r\n[![ESP8266](https://img.shields.io/badge/ESP-8266-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp8266)\r\n\r\n[![ESP32](https://img.shields.io/badge/ESP-32-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32)\r\n[![ESP32](https://img.shields.io/badge/ESP-32S2-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32-s2)\r\n[![ESP32](https://img.shields.io/badge/ESP-32C3-000000.svg?longCache=true&style=flat&colorA=CC101F)](https://www.espressif.com/en/products/socs/esp32-c3)\r\n\r\n\r\n# espFOTA\r\n\r\n**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.\r\n\r\n## Table of Contents\r\n\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n  - [Setup](#setup)\r\n  - [Network Status Indicator](#network-status-indicator)\r\n  - [Automatic Update Check](#automatic-update-check)\r\n- [Example Node.js Server](#example-nodejs-server)\r\n- [Important Notes](#important-notes)\r\n\r\n## Features\r\n\r\n- Easy configuration for OTA updates.\r\n- Automatic Wi-Fi connection management.\r\n- Continuous update checks with automatic application of updates.\r\n- Network status indicator using GPIO pin.\r\n\r\n## Installation\r\n\r\n### Installing with mip\r\n\r\nPy-file\r\n```python\r\nimport mip\r\nmip.install('github:raghulrajg/espFOTA/espFOTA.py')\r\n```\r\n\r\nTo install using mpremote\r\n\r\n```bash\r\n    mpremote mip install github:raghulrajg/espFOTA\r\n```\r\n\r\nTo install directly using a WIFI capable board\r\n\r\n```bash\r\n    mip.install(\"github:raghulrajg/espFOTA\")\r\n```\r\n\r\n### Installing Library Examples\r\n\r\nIf you want to install library examples:\r\n\r\n```bash\r\n    mpremote mip install github:raghulrajg/espFOTA/examples.json\r\n```\r\n\r\nTo install directly using a WIFI capable board\r\n\r\n```bash\r\n    mip.install(\"github:raghulrajg/espFOTA/examples.json\")\r\n```\r\n\r\n### Installing from PyPI\r\n\r\nOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from\r\nPyPI <https://pypi.org/project/micropython-espFOTA/>`_.\r\nTo install for current user:\r\n\r\n```bash\r\n    pip3 install micropython-espFOTA\r\n```\r\n\r\nTo install system-wide (this may be required in some cases):\r\n\r\n\r\n```bash\r\nsudo pip3 install micropython-espFOTA\r\n```\r\nTo install in a virtual environment in your current project:\r\n\r\n```bash\r\n    mkdir project-name && cd project-name\r\n    python3 -m venv .venv\r\n    source .env/bin/activate\r\n    pip3 install micropython-espFOTA\r\n```\r\n\r\nAlso see [examples](https://github.com/raghulrajg/espFOTA/tree/main/test).\r\n\r\n## Usage\r\n\r\n### Setup\r\n\r\n1. **Wi-Fi and Server Configuration:**\r\n    - `SSID`: Your Wi-Fi network name.\r\n    - `Password`: Your Wi-Fi network password.\r\n    - `host`: The server endpoint where the update file is hosted.\r\n\r\n2. **Example Program:**\r\n\r\n    Save the following code in a file named `main.py` on your MicroPython device:\r\n\r\n    ```python\r\n    import espFOTA\r\n\r\n    # Avoid the GPIO pin number 2 because of predefine pin (Network status indicator)\r\n\r\n    # Server connection config\r\n    host = \"package.xyz.com/newversion\"\r\n\r\n    # WiFi Network connection config\r\n    SSID = \"YOUR_APN_NAME\"\r\n    Password = \"YOUR_APN_PASSWORD\"\r\n\r\n    OTAUpdate = espFOTA.espFOTA(SSID, Password, host)\r\n\r\n    def loop():\r\n        while True:\r\n            # Put your code here\r\n            OTAUpdate.run()\r\n\r\n    if __name__ == '__main__':\r\n        loop()\r\n    ```\r\n\r\n    - **SSID**: Replace with your Wi-Fi network name.\r\n    - **Password**: Replace with your Wi-Fi network password.\r\n    - **host**: Replace with your server's URL endpoint where the OTA update file is hosted.\r\n\r\n### Network Status Indicator\r\n\r\n- The device uses GPIO pin 2 as a network status indicator.\r\n- If the Wi-Fi network is not connected, the LED on GPIO pin 2 will turn on.\r\n- Once the Wi-Fi is connected, the LED will turn off.\r\n\r\n### Automatic Update Check\r\n\r\n- The `OTAUpdate.run()` method continuously checks for updates from the specified host.\r\n- If an update is found, it is automatically downloaded and applied.\r\n- The device will restart to apply the new firmware.\r\n\r\n## Example Node.js Server\r\n\r\nTo serve the OTA update file, you can set up a simple Node.js server. Here is an example:\r\n\r\n```javascript\r\nconst http = require('http');\r\nconst url1 = require('url');\r\nconst fs = require('fs');\r\n\r\nconst server1 = http.createServer((req, res) => {\r\n  const parsedUrl = url1.parse(req.url, true);\r\n  const pathname = parsedUrl.pathname;\r\n  if (pathname === '/download') {\r\n    const filePath = `filepath/ota.py`;  // Path to your OTA update file\r\n\r\n    // Send the bin file to esp32\r\n    serveFile(res, filePath);\r\n  } else {\r\n    res.writeHead(404, { 'Content-Type': 'text/plain' });\r\n    res.end('Not found');\r\n  }\r\n});\r\n\r\nfunction serveFile(res, filePath) {\r\n  const stat = fs.statSync(filePath);\r\n  const fileStream = fs.createReadStream(filePath);\r\n  res.writeHead(200, {\r\n    'Content-Type': 'application/octet-stream',\r\n    'Content-Length': stat.size,\r\n    'Content-Disposition': 'attachment; filename=' + \"ota.py\"\r\n  });\r\n  console.log(stat.size);\r\n  fileStream.pipe(res);\r\n  console.log(\"Downloaded\");\r\n  fs.unlinkSync(filePath); \r\n}\r\n\r\nserver1.listen(3000, () => {\r\n  console.log('Server listening on port 3000');\r\n});\r\n```\r\n### Server Setup:\r\n\r\n- Save the above code in a file, e.g., `server.js`.\r\n- Ensure you have Node.js installed.\r\n- Run the server using the command: node `server.js`.\r\n\r\n### Endpoint: \r\n\r\n- The server listens on port 3000. The OTA update file should be accessible at `http://<server-ip>:3000/download`.\r\n\r\n## Important Notes\r\n\r\n- File Naming: The example program file name must be `main.py` on your MicroPython device.\r\n- Wi-Fi and Host Configuration: Ensure that the SSID, Password, and host variables are correctly set to match your network and server configurations.\r\n- Update Check Frequency: The `OTAUpdate.run()` method continuously checks for updates. Adjust the frequency or conditions within the loop function as needed.\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\"espFOTA: An OTA (Over-the-Air) update library for ESP8266, ESP32, and other devices supporting MicroPython.",
    "version": "1.0.0",
    "project_urls": {
        "Source": "https://github.com/raghulrajg/espFOTA"
    },
    "split_keywords": [
        "ota",
        " fota",
        " update",
        " microcontroller",
        " micropython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ca0d409ceece4ccebc71c207cbe20e47922230f19d4c2dd2685470d5037e0ae9",
                "md5": "4fe7bc314d42560b9da39c39cdd7fc00",
                "sha256": "5c794a648d806c98e03fcc7fd362b91eb921240593402a24c4eebe968c15a129"
            },
            "downloads": -1,
            "filename": "micropython_espFOTA-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4fe7bc314d42560b9da39c39cdd7fc00",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 17211,
            "upload_time": "2024-06-15T03:55:53",
            "upload_time_iso_8601": "2024-06-15T03:55:53.043073Z",
            "url": "https://files.pythonhosted.org/packages/ca/0d/409ceece4ccebc71c207cbe20e47922230f19d4c2dd2685470d5037e0ae9/micropython_espFOTA-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bb49edda7251b041e27bbcbb56cff1488c137dba324f5a3329c97009ad22c89f",
                "md5": "e1ce729cd6afac4a3900fdcd6c3662a0",
                "sha256": "90dea466abede2ad4550038760b157c4dd691b41d56996a9288dcdb1a681700e"
            },
            "downloads": -1,
            "filename": "micropython-espFOTA-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e1ce729cd6afac4a3900fdcd6c3662a0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5244,
            "upload_time": "2024-06-15T03:55:55",
            "upload_time_iso_8601": "2024-06-15T03:55:55.034287Z",
            "url": "https://files.pythonhosted.org/packages/bb/49/edda7251b041e27bbcbb56cff1488c137dba324f5a3329c97009ad22c89f/micropython-espFOTA-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-15 03:55:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "raghulrajg",
    "github_project": "espFOTA",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "micropython-espfota"
}
        
Elapsed time: 0.35662s