redis-cloudclient/redis-cloudmanager

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
dwight.hubbard
Posts: 38
Joined: Mon May 16, 2016 6:35 pm

redis-cloudclient/redis-cloudmanager

Post by dwight.hubbard » Sun Jul 03, 2016 9:34 am

I finally have a bit of a working proof of concept for one thing I'm dong with redis.

redis-cloudclient is a simple client that connects out to a redis server and watches a simple queue for incoming commands. It also uses the redis server for storage. Currently the only operation it supports is exec which executes one or more commands and streams the result back to the server where it can be read and displayed by the caller without storing everything in ram or flash on the microcontroller.

Multiple boards can connect to the same redis server and be controlled centrally.

Explanations can be confusing, so here's some examples using the script to manage multiple esp8266 boards:

The client sends a heartbeat and status information to the redis server. The list command lists the boards that have registered with the server:

Code: Select all

$ micropython_board_manager list
Platform    Name                                              
esp8266    nodemcu1                                          
esp8266    nodemcu2                                          
For this example, I have a small python script that prints some basic information.

Code: Select all

$ cat /tmp/info.py
import machine
import sys
import ubinascii

print('Platform', sys.platform)
print('Version', sys.version)
print('ID', ubinascii.hexlify(machine.unique_id()))
To run the script we pipe it to the "micropython_board_manager" command. The board names in the execute command support hostlists range expansion. The example command will run on boards named nodemcu1 and nodemcu2.

Code: Select all

$ cat /tmp/info.py|micropython_board_manager execute nodemcu[1-2]
******************************************************************************
Executing on 'nodemcu1'
******************************************************************************
Platform esp8266
Version 3.4.0
ID b'9efaf100'

******************************************************************************
Executing on 'nodemcu2'
******************************************************************************
Platform esp8266
Version 3.4.0
ID b'd5d00400'

$
A couple of notes:
  • Currently the client doesn't work on the Wipy currently (the board hangs).
  • The client doesn't currently support running with a redis serial proxy to allow usage over a UART.

dwight.hubbard
Posts: 38
Joined: Mon May 16, 2016 6:35 pm

Re: redis-cloudclient/redis-cloudmanager

Post by dwight.hubbard » Tue Nov 08, 2016 8:28 am

I've finally got some time to work on this again. Since I've been flashing a bunch of boards with the client I created a flash utility for it. In case it might be useful for others.

1. I created a python package to flash and configure my nodemcu boards with micropython and the redis-cloudclient.

For example, this installs the flasher and brings up an esp8266 on wifi network mywifi and has it register as board nodemcu1 on the cloudmanager server.

Code: Select all

$ pip install cloudmanager-micropython-esp8266
$ flash_esp_image --wifi_ssid mywifi --wifi_password mywifipassword --cloudmanager_server 192.168.1.127 --cloudmanager_port 18266 --name nodemcu1 
    esptool.py --port /dev/ttyUSB0 --baud 115200 erase_flash
    esptool.py v1.2.1
    Connecting...
    Running Cesanta flasher stub...
    Erasing flash (this may take a while)...
    Erase took 9.0 seconds
    esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --verify --flash_size=32m --flash_mode=qio 0 /home/dwight/.virtualenvs/cloudmanager-micropython-esp8266/local/lib/python2.7/site-packages/cloudmanager_micropython_esp8266/firmware/firmware-combined.bin
    esptool.py v1.2.1
    Connecting...
    Running Cesanta flasher stub...
    Flash params set to 0x0040
    Writing 557056 @ 0x0... 557056 (100 %)
    Wrote 557056 bytes at 0x0 in 48.3 seconds (92.3 kbit/s)...
    Leaving...
    Verifying just-written flash...
    Verifying 0x8734c (553804) bytes @ 0x00000000 in flash against /home/dwight/.virtualenvs/cloudmanager-micropython-esp8266/local/lib/python2.7/site-packages/cloudmanager_micropython_esp8266/firmware/firmware-combined.bin...
    -- verify OK (digest matched)
    
    >>> 
    >>> import os
    >>> os.mkdir('etc')
    >>> from bootconfig.config import get, set
    >>> set('wifi_ssid', 'mywifi')
    >>> set('wifi_password', 'mywifipassword')
    >>> set('redis_server', '192.168.1.127')
    >>> set('redis_port', '18266')
    >>> set('name', 'nodemcu1')
    >>> import bootconfig.service
    >>> bootconfig.service.autostart()
    >>> import redis_cloudclient.service
    >>> redis_cloudclient.service.autostart()
    >>> import machine
    >>> machine.reset()
$
The utility will flash a plain esp8266 flash image if command line arguments aren't provided.

dwight.hubbard
Posts: 38
Joined: Mon May 16, 2016 6:35 pm

Re: redis-cloudclient/redis-cloudmanager

Post by dwight.hubbard » Thu Nov 17, 2016 5:48 pm

I've add functionality to allow cloudmanager to install packages on the managed boards without requiring upip on the board. I.E. the download, unpack, and dependency resolution of the package installation is done on the management server.

I also added some changes to make it easier to get working on the esp8266.

The steps to get it working now are:

1. Install

Code: Select all

    $ pip install micropython-cloudmanager micropython-cloudmanager-esp8266
2. Start the server

Code: Select all

    $ mbm server-start
3. Flash micropython to the esp8266 board and configure it (repeat 3 times)
Plug in the esp8266 board (I've tested on nodemcu, wemos-d1 and adafruit huzzah). The nodemcu and wemos-d1 are pretty much plug and play the huzzah requires manually putting the board into flash mode.

Code: Select all

    $ flash_esp_image --wifi_ssid mywifi --wifi_password mywifipassword
4. Verify the boards connect to the server

Code: Select all

     
     $ mbm board-list
    Name       Platform                                           State
    esp8266-1  esp8266                                            idle
    esp8266-2  esp8266                                            idle
    esp8266-3  esp8266                                            idle
    $
5. Install a package on all the boards

Code: Select all

$ mbm board-install esp8266-[1-3] micropython-logging
Installing package 'micropython-logging'
Copying file to esp8266-1:lib/logging.py
Copying file to esp8266-3:lib/logging.py
Copying file to esp8266-2:lib/logging.py
6. Execute some code that uses the new package

Code: Select all

    $ mbm board-execute esp8266-[1-3]
    import logging
    logging.info('Example log message')
    ## Executing on 'esp8266-1' ####################################################
    INFO:None:Example log message

    ## Executing on 'esp8266-3' ####################################################
    INFO:None:Example log message

    ## Executing on 'esp8266-2' ####################################################
    INFO:None:Example log message

    $

Post Reply