CC1 devtools for image conversion and log extraction

During development of dataviews to integrate your application with the CC1, it is often neccessary to get the logs from the device, or create images in the correct format for the epaper screen (either to upload to the SD card, or to put into allocation or MQTT json files)

The devtools package has python scripts to do these operations.

convert image files

Images used on the device must be in a 4 bit gray scale format derived from PortableBitMap format. This is a binary uncompressed format with 4 bits per pixel, labelled as gs4 (gray scale 4 bit).
Conversion to this format must be done before giving the image to the device, generally on a PC. This must have python10+ and the CV2 libraries installed (pip3 install cv2). To use the images can be:

  • stored on the disk (in /flash/lib/imgs/gs4 or /sd/imgs/gs4, as .gs4) and referenced by imgId being the filename (no path or extension)
  • passed as base64 encoded binary whereever a imgId is expected (icon refs, widget values).

Mass conversion

In resources/img-gen, the img2gs4.py, img2pbm.py scripts allow mass conversion of images from a directory into the .gs4 (4 bit gray levels) and .pbm (portable bitmap B&W) images. These are run automatically in the gitlab CI pipeline to generate the sd card resources zip artifact.

Individual file conversion to GS4 and B64 string

python img2gs4b64.py -s <source PNG> [-d <outputfile>] [-b64] [-h <height>] [-w <width>]

The img2gs4b64.py tool converts a specific PNG image to a gs4 image, which can be output:

  • to a binary file (suitable for uploading to the device’s /flash or /sd disks)
  • to a base64 string in a file (-b64 option)
  • to a base64 string on stdout (-b64 option with no -d )

This b64 text string can then be used directly as a ‘value’ for a icon or button widget in a DV json or as a attribute for a widget send via MQTT.

The -h and -w options allow to resize the image bigger or smaller than the input image. If only one of the new dimensions is given then the other is calculated to preserve the proportions of the input image.

download logs

The code will generate logs (error, warn levels by default). To get these logs onto the PC, use the showlogs.py script. To ensure the FTP server and wifi AP are available, reboot the CC1 into update/FOTA mode (BLUE LED) before running the script. Then connect the PC to the correct wifi AP for the device (infrafon-<last 4 digits>) and do:

python showlogs.py

The log files will be in the ./logs directory.

By default the log level is at error and warning only. To change this we upload a specific ‘device_dev’ files (which sets the mode after a reboot) to ask it to also have INFO logs. In the firmware update zip directory:

python upload.py -s built/device_dev_runlogs -d /flash/device_dev -ssid <AP>

To change back to error/warning only we do

python upload.py -s built/device_dev_run -d /flash/device_dev -ssid <AP>

sideload allocate data / simulate return

Sometimes we need to get the device to get its allocation data from a local file, not from the IES. Use the allocate.py script to do this, and the return.py to simulate the request to de-allocate.