Espressif ESP-Mesh updates their App with a new UX

About a month ago I started learning to use ESP-IDF and got very interested in Espressif Mesh Lamps. It’s a lot of fun for me to create my own ESP-Mesh LEDs lamps with this technology. But as with everything I touch that is open-source, apart of being a user, I try to collaborate and made the thing better. That’s the spirit of open source, you are a user, but also at the same time your opinion counts and usually it’s welcomed.

Comparison from previous ESP-Mesh App and new upcoming version:

2018 version
Esp-Mesh App
03/2019 new version

Updates resume

  • More integrated and compact UX. Now On/Off switch is in the same screen allowing for easier usability
  • Doing White with RGB is now possible. Click on the center and the light will turn on the 3 colors at the same time (New feature)
  • Warm/Cold switch is also better signalized and more usable.

I really like the update and I think is a significant improvement over the last version.

Here some selfish pictures of my last lamp projects ;)

Esp-Mesh Lamp with modified software to enable Oled-display (Heltec WiFI32 board)
Esp-Mesh with one RGB 8Watts LED
Esp-Mesh mini projector (Stage type traditional lamp)

ESP-IDF Libraries in Arduino framework

I started to dig a bit more into the Iot development network from Espressif with the intention to slowly learn something new. All the official examples of Mesh lights, ESP32-Camera and ESP-WHO that presents a preliminary version of face recognition are built on the top of the IDF.

So sooner or later, I think will be the official way to do “internet of the things” devices with these Boards. But I’m still not ready for it, I need to do simple examples and experimenting before taking over and do something for real.

So the first things I tackled on is to take this libraries “as is” and use them in existing Arduino framework projects. And it’s fully possible, below is a small example about this using the TTGO Camera with Pir sensor

https://github.com/martinberlin/esp32-camera-bme280

So far it features:

  • camera_index.html template loaded from the SPIFFS so you can modify it for your project (No Gziped non-editable file)
  • Added V-Flip setting that was not existing in the original example
  • Libraries loaded using platform.io file

This is my humble try to make a hackeable and modificable esp32 Camera example using ARDUINO as a framework but with the official Espressif Camera Libraries.

One important step is that without using the IDF, just adding the libraries in plataform.io project configuration file:

platform = espressif32
framework = arduino

lib_deps =
https://github.com/espressif/esp32-camera.git

It won’t compile. The reason is that it tries to find the C header files but they do not have the needed mapping out of the box if you use framework: arduino. It will complain that:

Compiling .pioenvs/ttgo-lora32-v1/libe0c/esp32-camera/conversions/jpge.cpp.o
.piolibdeps/esp32-camera/conversions/jpge.cpp:11:18: fatal error: jpge.h: No such file or directory

And the file is there but in another directory. So my workaround was to add this directory in the build_flags configuration:

build_flags =
-I.piolibdeps/esp32-camera/conversions/private_include
-I.piolibdeps/esp32-camera/sensors/private_include
-I.piolibdeps/esp32-camera/driver/private_include

After this it compiles without errors.

Some notes and references for this post

Think about C header files as your interfaces, your function prototypes! Code organization is very important.
3D-models for the TTGO Cameras available in Thingiverse, my own prototype design (be aware!)

New ESP-Mesh RGB+White Light soldered. You can do your own for about 10€ materials and 2 hours soldiering ;)
Small preview:

Starting to do smart-home appliances with ESP-Mesh

ESPMesh reduces the loading of smart light devices on the router by forming a mesh with the smart light device.”

I’ve started months ago getting some smart lights for home and I’ve chosen Osram since it was about half the price than Phillips VUE. But the thing with this systems, though they work nice and with very little configuration, is that you need always a “Gateway”. A central point that receives signals and then send via Radio frequency to the lights what they have to do.

The Espressif ESP-Mesh took a different approach: Every device is a network member making a Mesh of interconnected devices. There is no gateway because there is no need for one.

There is also a very important point that is very interesting if you are a maker like me. It’s open source. That means you don’t need to buy a 60€ light to test it, you can just go to the ESP-Mesh github repository and download ESP-Mesh-Light example to compile it in one of your existing ESP32 Boards. Then you can get easily something like this working :

So what I’m working on the free time to take a rest from another pending projects is to take this PWM output and amplify it using a 74HC125 Quad Bus Buffer to power more than one led.

For those interested in reproducing this example:

https://github.com/espressif/esp-mdf/tree/master/examples/development_kit/light

Command lines to execute the compilation are only 2:

make menuconfig
make erase_flash flash

Compile this into your ESP32 and then download Espressif official Android App or if you are using I-phone / I-Pad just search for “ESP-Mesh”
The Mesh devices are configured using Bluetooth so keep in mind to have this enabled on your device. Instead of taking the “WiFi Manager” Approach, using an App, you have the benefit that you can just send the WiFi Credentials plus configuration directly to the ESP32.

Simple IoT image logging using BigIot.net

Since beginning of 2019 I’m participating in a project called “Low cost / low power sleep / WiFi Camera” so I purchased a couple of low cost boards, between them the LilyGO ESP 32 Camera.

ESP32 Lilygo 800×600 pix SVGA Camera. If you need a case, made one here

BigIot.net is an interesting IOT API site

Not only an API but a very interesting infrastructure that is also possible to link BIGIOT with WeChat allowing to “chat” with your device and use it for Smart home or just to check what was the last image uploaded.
In my fork of this ESP32 Camera, since the original looks a bit unmaintained without even an issue board, I added some better display information:

https://github.com/martinberlin/ESP32-Camera BIGIOT_UpdateImage.ino

This example shows how to set up an automatic camera that takes pictures every 20 seconds and sends them like an API Post push to BigIot.
So far so good, it works at first glance. The issue is that BigIOT is all in Chinese and there is no english. So if you consider that a problem then you can stop here. I didn’t because I think the Chinese know hell about this and they are leading the IoT world for a good reason.

So I translated it as I could just to register and get this pieces of information:

#define BIGIOT_API_KEY "KEYHASH" ( 智能设备 Devices -> APIKEY)
#define BIGIOT_DEVICE_ID "INTEGER"
#define BIGIOT_INTERFACE_ID "INTEGER"

BigIOT Registration -> 注册



A

After registering you just have to open the activation Email and you are good to go. Just log in the Admin Panel and try to feel at home. Most important parts are:

智能设备列表 List of your Devices -> Add a “Camera device”

数据接口列表 List of your Inputs -> This is the Interface, so just make an “Upload interface”

And that are the two IDs you need, device ID and interface ID. After that and compiling this, the small camera is going to start pushing pictures to BigIOT and you can just click on the stats on the interface area and start checking the pictures when you are away.

Very good to control for example a 3D printer that you leave at home finishing something. This is the result:

Interface statistics
BigIOT Interface statistics
ADDITIONAL INFO 

https://gitee.com/hejinlv/ESP32/blob/master/ESP32_bigiot_LED/
Here there is a great example on how to Listen to Commands to interact with WeChat

Espressif multi-SPI workshop

Serial parallel interface was developed by Motorola in the eighties and is the standard or short communication in embedded devices.

Left side: ESP32 master. SPI single slave example. Right side: Arducam camera slave
( on SS low camera communicates with master )

The data transmission is explained in detail in the Wikipedia SPI article. But basically is along this lines and we will add some code examples below:

  1. The bus master sets up the clock using a frequency supported by the Slave device.
  2. Master selects the slave device with a logic level 0 on the select line.
  3. During each SPI clock cycle a full duplex data transmission occurs. Master sends a bit on the Master Output Slave In line (MOSI) and the slave reads it. The slave sends a bit on the MISO line and master reads it.
Image source: Wikipedia SPI article

That’s basically the essence of it. There is much more happening under the hood and it’s explained with more in detail on the referenced article. The interesting part of the SPI interface is that we can have many Slaves communicating with the master, since when the SS line is HIGH the slave ignores the master, so we can basically have a different SS (Or Chip select line) per device. So you can use the same Clock, Mosi and Miso to communicate with many SPI devices as long as the data communication happens with one device at the time.

The problem appears when you need to communicate with two different SPI devices at the same time

For example, in the WiFi Camera project, we made an experimental model with a st7735 small 128×128 pixels color TFT display that is also SPI. So if you want to make a progress bar in the moment where we are reading the Camera memory, you cannot use the same SPI interface, because you will share the data line and get a corrupted image.

Maybe there is a way to do it that I’m not aware of. When yes, then please add a code example ;) So my intuitive solution to the problem was to use a second SPI interface, completely independent from the Camera SPI. So that was a nice idea, but implementing it was not so nice, and the issue is that most of the libraries instantiate SPI like this:

SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, SS);

Or simply:

SPI.begin(); // To use default GPIOs

At this point we could make a stop and mention that the ESP32 has some custom SPI gpios that are by default used when you do an SPI.begin() without any values. And that is very well explained in the Espressif documentation for SPI master driver:

IOMUX pins for SPI controllers are as below:

Pin NameHSPIVSPI
GPIO Number
CS0*155
SCLK1418
MISO1219
MOSI1323

So if I understand well and you see the GPIO writings on most ESP32 boards SPI.begin() without parameters starts the interface using the VSPI gpios also 18,19 and 23. But what happens if you want to use another GPIOS ?
No problem, just start SPI.begin() with the GPIOs you want to use. That as long that you don’t need to use a second SPI device. Because when you are instantiating SPI at a global level, you are instantiating a class that will use that GPIOs for all your program. So the solution is to use two different classes and there is a very good example about this in the SPI Multiple buses example on Espressif repository.

The problem is many libraries have not considered the possibility of multiple SPIs

At this point I had a solution but I was still far away of implementing it. Arducam library is pretty old and I could say, not maintained for the future generations of ESP32 chips. Even the SPI instantiation has to be done outside the Lib although the SPI.transfer and so on are fixed inside it. Too bad. TFT st7735 is a very nice lib and well maintained so it lets you define your own SPI gpios in the configuration. So after some minutes of doubt I decided to recode the SPI functions of the Arducam and make them mine. So that is what I did, to recode the SPI functions, leaving arducam library as a minimal I2C communication lib and taking SPI to my own command. Not a big deal, just check what functions are in charge of SPI.transfers and so on, copy them to your own and replace this by your own implementation.

We start our own class in a global level:


SPIClass * hspi = NULL;

void setup() {
   hspi = new SPIClass(HSPI);

  //        sck, miso, mosi, ss
   hspi->begin(16, 0, 4, CS);
   hspi->setFrequency(4000000);  // 4 Mhz
}

And that is it. After this we will use this hspi for our camera communication, leaving the other SPI for the display. It worked out, after some minutes of tweaking and burning my fingers changing wires from one GPIO to another.

https://twitter.com/martinfasani/status/1078585069458075648


PlatformIO: An alternative to Arduino IDE and a complete ecosystem for IoT

PlatformIO Logo

As an introduction I would like to make clear that I’m not a C++ advanced coder or IoT professional, I do this just because it’s a challenge, and because it’s a lot of fun compared to my 9 hrs/5 days a week web developer doing PHP and Admin panels for clients in Germany. Two months ago I started tinkering with SPI Cameras and the Espressif systems boards and that’s how this open source project was born. So far I was using Arduino since I do not need a super IDE, sometimes I also edit the code with vi or gedit instead of open a monster IDE that will eat your CPU alive. But gladly this is not the case. I was since long looking for a competitive alternative to Arduino when this github issue on the FS2 Camera Project called my interest:

tablatronix commented 8 days ago

I had to manually install this button library as it is not in platformio , is it in arduinos?

And that’s how after a few clicks I discovered Plaftormio.org that according to their home page it’s an open source IoT ecosystem. But what interested me more than this is the subtitle:  “Cross-platform IDE and unified debugger. Remote unit testing and firmware updates

So instead of answering tablatronix issue, I started installing this new IDE, that happened in a breeze.
1. First thing is to install the VS CODE Version. I choosed the Visual Studio code option since it has more features. Microsoft’s Visual Studio Code is the base and PlatformIO is built on the top of this.

2. Go to “Extensions” and install PlatformIO IDE “Development environment for IoT, Arduino, Espressif (ESP8266/ESP32)”

platformio IDE extensions is marked in RED just before PlatformIO logo

3. In my case since I used Arduino IDE before, go to PlatformIO alien face logo and select “Import project from Arduino”. Then select the folder where your Arduino project is and PlatformIO will create a Workspace for you with all the necessary structure.

4. Adjust serial monitor baud rate.  If you are using Espressif chips edit platformio.ini and add the following line at the end:

monitor_baud = 115200

This will make your serial work in the right baud rate for ESP8266 /ESP32 (Serial is the plug icon in the bottom just before the Terminal > icon)

5. FS Data. If you are using SPIFFS that in Arduino is the /data folder inside your sketch you will notice that in PlatformIO this folder needs to be at the root level. So you can simply move it one directory above. To upload SPIFFS data use the following command in the terminal:

pio run --target uploadfs
IMPORTANT: As difference with Arduino if you try to save a file in /1.JPG here you will get it saved on:
/spiffs/1.JPG so create this folder on /data or you will get; VFSFileImpl(): fopen(/spiffs/1.jpg) failed

6. Libraries in PlatformIO live inside a folder on your project called .piolibdeps Thanks god, they are not distributed on 3 different parts, like it happens with Arduino (Some in Arduino/libraries, some in Programs/Arduino/libraries and so on) but are there available for you in just one place :)
To install a new library is very easy, just go to PlatformIO.org/lib and type the name of the library to search. If found copy the resultant line in the Terminal just like point 5 and the IDE will look this up for you and download it using github to the  .piolibdeps folder.

pio lib install "WifiManager"

Sometimes you will need a library in a special branch and there is also an easy way to do this. Just use :

pio lib install <repository#tag> 

// Install development version of WifiManager library
pio lib install https://github.com/tzapu/WiFiManager.git#development

7. If you use Arduino before it’s possible that you used some of it’s constants. So if your sketch compiles, but it does not runs like expected try to add this include line at the beginning

#include <Arduino.h>
Including Arduino.h at the beginning of the sketch

As a footer note I must make clear that it takes some time to get accustomed to the new IDE. But it comes with a great benefit as it shows you much better C++ warnings, it’s prettier to use, and has the advantage that you can Ctrl+Click and navigate between different classes. Something that it was not possible to do with my old IDE. And the most beautiful update is that all libraries are in a single place per Project, like it should be, leaving you a clear idea of how much code and dependencies you are adding into your sketch.

In FS2 project porting it to the ESP8266 Wemos board this happened like a breeze. And it was just the fact of upgrading my code to use OneButton library. adding the include Arduino.h and that is. After uploading SPIFFS data and the new code, the camera was ready to be used. Now it’s not always that easy. trying to compile the same code to an Heltec ESP32 board, I got SPI communication issues with the camera and I’m still fighting with it.

UPDATE: I found what is going on here, and it’s that there are some problems with my sketch that uses I2C and wire library to comunicate with the Camera on the Heltec ESP32 environment. Error message is:
i2cCheckLineState(): Bus Invalid State, TwoWire() Can’t init. I solved it updating the platformio.ini configuration file to use:
board = lolin_d32
So using this board it compiles and works correctly. No idea why it does not using heltec_wifi_lora_32 I will have to research more.

Additional links of interest:

Source filter: src_filter
This option allows to specify which source files should be included/excluded from build process. It could be useful to keep the same core for ESP8266 and ESP32 but including different files to support both. So far I’ve been using 2 different branches something that is hard to maintain for obvious reasons.

Library dependencies: lib_deps declaration in platformio.ini
Like composer for PHP, this IDE offers a way to declarate your libs in the ini file. To check how a professional software for 3D-printing does take a look in Marlin configuration file. This is a very important point to keep in mind since after the lib_deps list is correctly added and tested, people testing your code just need to hit “build” to download them, saving a huge amount of time. This are FS2 library dependencies.

FS2 Camera project

If you are interested to build your own WiFi Camera for around 40€ of components and maybe 5€ of 3D-printed case, then check this project on github:

https://github.com/martinberlin/FS2

I’m giving out in december ten free 3D-printed cases, if you are interested on getting one and putting together a WIFi Camera please choose between Black PLA, black PETG or RED transparent and comment in this post. You can send me the address later per private message or in twitter. Thanks for your interest!

Chunk uploading files via WiFi with Espressif boards

Derived from this FS2 Camera project I would like to make an sequential uploader that matches this use-case.
Any file major than 50 Kilobytes will be uploaded in chunks of 50 Kb, using the following workflow:

Picture.jpg (150 Kb) -> Read fifo from Arducam
                                              -> Send first 50 Kb to upload API along with an md5 hash of this first 50 Kb (Called API from now on)

API uploads this first 50 Kb chunk and returns a true if md5(File)==hash received if not returns false

-> ESP board receives this signal and repeats the upload if it’s false up to N times (3 or 4 times at least)

When sending the last part to API, we will add some parameter like EOF = 1 or something in this direction so the API understand this will be the last part to receive. And in successful upload of this last part the server side API will put this chunks together and return the full URL to the image.

This can be the basis to upload big images with consistency.

As you can see here uploading any File that is larger than 40 / 50 Kb is already a big challenge.  And I still didn’t saw this implemented anywhere so it will be a great challenge to build something in this direction


ESP-32 a new standard of speed and connectivity

Developed by Espressif the ESP32 brings a new standard in low-cost WiFi boards. After porting one project to this new board I must say that it’s very similar to the ESP8266 and most code except some updated libraries, should work with minimal effort. 

ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a TensilicaXtensa LX6 microprocessor in both dual-core and single-core variations and includes in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power-management modules.” – Wikipedia description

What is still pending on my side is to compare power consumption and other details as WiFI range (With and without antenna) between ESP8266 and this new ESP32. But overall I’m really excited to build things on the top of this.

Combined with @tablatronix amazing WiFi Manager library it gives creators the possibility to have an independant IoT device with custom configuration, autoconnect and full info of the device.

It’s still pretty much on development so they are many things that are normally worst at the beginning (SPI Flash File System for example, a hell lot slower and at the moment only usable for small configuration files for me) But that’s normal, things are going to be fixed over the time, and hell it’s open source so let’s give these guys a hand and report new findings so they can fix it as soon as possible.

Yesterday I found the time to refactor my digital Camera project to use ESP32 (Makerfocus Heltec board). If you are interested in seeing the code updates please my commits in the board/esp32-oled branch.


So far still on my tests I won’t expand myself too long on this one. Giving some pointers and links for further research below.

Arduino Core
https://github.com/espressif/arduino-esp32

SPIFFS (ESP8266 code should be refactored to reflect library update)
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino

PINS
https://github.com/makeitlabs/ratt/wiki/ESP32-Pin-Mapping

Using the OLED built in the Makerfocus ESP32

The ESP32 directory when installed using Arduino in Ubuntu is:
/home/martin/.arduino15/packages/esp32 -> I find weird that Arduino  keeps libraries in 3 different Folders making it very confusing to see library source code.


Uploading your pictures directly into the cloud

Yesterday I found some time to make an example of image push to the Cloud using Seafile storage. The idea is that instead of making a regular file upload that needs some kind of Backend gallery to preview the pictures, we can have a different take, like pushing the picture directly to your Cloud-storage.

WiFi Camera (C++) > API Endpoint (PHP) > Seafile cloud (Python/C)

So the first thing I tried is to browse the Seafile Web API manual and repeat in command line the curl commands. And then I found in packagist this great library that is a wrapper for all commands to implement them easily on your script.

For sure this would be also possible to do it without the middleware PHP, directly in C++ on the Espressif  SoC,  but I would like to have proper error handling and also to save a copy of the image in the case that the Cloud->push fails for any reason. It can be also a very complicated task considering they are at least 3 API calls using the bearer Auth token.

SeaUP

Short for Seafile upload this a code-example to make a PHP File upload using Seafile API and a simple JSON configuration

Repository lives here: https://github.com/martinberlin/seaup

Configuration is easy:

1– You need to obtain a Token

curl -d “username=username@example.com&password=123456” https://yourseafileserver.com/api2/auth-token

{“token”: “14fd3c026886e3121b2ca630805ed425c272Xxxx”}

2- Edit the sea-config.json and add it along with your seafile server and repository ID settings

{
  "seafile_host": "https://storage.luckycloud.de",
  "token": "14fd3c026886e3121b2ca630805ed425c272Xxxx",
  "repository_id": "Is on the last part of Url when opening a library: #my-libs/lib/REPOSITORY_ID"
}

3- That’s it ! You are ready to open the test provided in the github repository and see if the image appears on the cloud

FS2 camera from Blender to production

In this entry, I wanted to document what is the process of making one of this cameras, starting from the 3D – model to the end product where you turn it on and connects to WiFi ready to take pictures.

After removing the support and sanding the round columns the first thing is to connect the front and back case together and see that they fit correctly. Usually, they do but PET is a tricky plastic to print and the end termination is a bit rougher than with PLA so it requires some post-production work. As an advantage, this plastic is stronger than PLA, and will stand a crash much better since it’s more elastic and resistant. I would say the best termination and strength balance would be to print this in ABS but I dislike the smokes and the fact that is also very difficult to print at home.

When this step is ready then it’s the time to heat up the soldier and prepare the ON/off switch and the shutter button. Then there are 8 cables more that go from the Arducam (2 or 5 mega version) to the Wemos D1, that is the responsible of uploading the picture to the cloud. This is a prototype for myself so it looks a bit messy but shows how it is at this stage:

3 pair of cables from the left to the right: Battery, ON/off and shutter button

Then comes the reality shock moment that is to connect the Wemos ESP8266 through USB to the computer and upload the program that will do the magic of receiving the JPEG image from Arducam and upload it to a php API endpoint. Usually, at this point there is something that needs to be corrected, but either nothing works or all is fine and dandy. I open the mobile hotspot and turn on the camera. See if connects, try to take a picture, preview it on the PHP-gallery.  Try to test timelapse mode, see it works, and that’s pretty much it. A new camera is ready to be delivered.

FS2 WiFi camera