We have prepared a free BIPES eBook to help interested people with a basic introduction to the Internet of Things and Embedded Systems using BIPES! There are two versions: one in English and one in Portuguese.
Embedded systems are everywhere: basically, they are miniature computers embedded in products, performing specific tasks. Some examples of products with embedded systems are automatic garage gates, access control systems, alarms, cars, refrigerators, televisions, cars, robots, automated industrial machinery and equipment, airplanes, and many others. Furthermore, these embedded systems can be connected to the Internet, allowing remote monitoring and control in the context of the Internet of Things (IoT). This book introduces the Internet of Things and embedded systems through hands-on activities with low-cost components using the ESP8266 module or the ESP32 module and MicroPython, a minimalist implementation of the Python 3 programming language for microcontrollers. The implementations are made through the BIPES programming tool (http://bipes.net.br/): Block based Integrated Platform for Embedded Systems, an open and free platform for programming using blocks, which offers an intuitive, practical, and fast way to develop embedded and Internet of Things applications for various platforms of embedded systems.
In addition to introducing basic concepts, the book also features programming examples for controlling devices, collecting data from sensors, sending data to the cloud, and building dashboards. Furthermore, all activities performed with BIPES do not require the installation or configuration of any software: to program embedded systems and IoT applications using BIPES, access BIPES online, and all activities can be done from the web browser, including uploading the code on the ESP boards, without the need of using Arduino IDE, or any other programming software. This book and BIPES can also help you learn the Python language, as programs made using blocks automatically generate Python language programs and can be edited and run on the board.
The book covers basic activities, such as building repetition structures, conditional decision structures, controlling output pins, reading the state of digital (GPIO) and analog input pins, managing time with RTC (Real Time Clock), managing files in the boards, connecting to WiFi networks and the Internet, sending data to the cloud using Message Queue Telemetry Transport (MQTT) platforms, handling errors, using timers and pulse-width modulation (PWM) in addition to explaining how to build subroutines and functions to modularize programs.
The book also helps readers to implement programs to control devices via the Internet, embedded web servers (HTTP), and use web services through HTTP requests to integrate applications made with BIPES with other systems and platforms, including weather forecasts, smartphone apps created using the MIT App Inventor, as well as Google Home and Amazon Alexa using IFTTT (If This Then That). Several complementary activities are also proposed with ESP8266 or ESP32 boards.
The book is free in PDF version, but you can also buy it on Amazon. By purchasing the book, you also contribute to the maintenance of the costs of the BIPES cloud project servers on the cloud, which makes BIPES freely available to everyone.
BIPES is a free and open-source platform for block-based embedded systems, IoT programming, and more (https://bipes.net.br/). BIPES generates code for CircuitPython and is entirely web-based, so no software install is needed. BIPES can be used as an IDE to program using CircuitPython using text-based programming, blocks, and other features.
Although this post is focused on the Franzininho WiFi with the ESP32S2, BIPES works perfectly with MicroPython based boards and should work with other boards based on CircuitPython.
This post shows some possibilities using BIPES + Franzininho WiFi + CircuitPython!
Our intention is to revisit the examples and instructions presented by Fábio and Diana (on the link above), but now, using BIPES (https://bipes.net.br/). The board must already have the CircuitPython installed to follow the activities, as explained by Fábio and Diana in the Franzinho WiFi documentation mentioned above. Considering CircuitPython is already installed on the board, no additional software or configuration needs to be done. Just access the BIPES and program / control your Franzininho WiFi board. It is recommended to use Google Chrome.
The objective of this first program is to test the connections, USB port access, send commands to Franzininho WiFi, and control an output pin (GPIO) to flash an external LED. USB connection is possible due to Web Serial API.
To create a program to blink the LED by BIPES, access BIPES (https://bipes.net.br/ide/) and choose the board on the top right area of the screen:
Next, try to connect to the board using the connect button:
After clicking on the USB port symbol, select Serial:
A list of devices will be shown. Select your Franzininho WiFi, which is powered by the ESP32-S2:
Click on the BIPES Console tab and try to send some Python commands to the board through this Console / Serial Terminal in the web browser:
With board connected, create the following program:
Use the left blocks toolboxes: Loops, Logic, Timing, and Machine ==> In/Out Pins.
You can also access the above program directly by clicking on the link below:
BIPES also allows you to plot data through an IoT dashboard, thanks to freeboard (https://github.com/Freeboard/freeboard). Use the “Show on IoT tab” block and the IoT tab. You can use this block multiple times and plot multiple values simultaneously:
And add a DATASOURCE of type “BIPES Serial, USB or Bluetooth. Define the datasource as ADC1, message ID 1, and refresh every 0.1 seconds:
After that, add some panes using the option ADD PANE:
Next, click on the + icon on the top right area of each pane and select the type you prefer. For this example, we used Gauge and typed datasources[“ADC1”] on the value field. Note that you can click on + DATASOURCE so that freeboard will help you enter the value with auto-completion. Also, define the Unit, minimum and maximum values.
We have also added a Timeseries (highchart) widget to another pane, with input values from the same datasource (ADC1), which allows a single (or multi) line real-time plot to be shown. And the result is:
Timing and synchrony
BIPES used a queue data structure to send data from the Console to the IoT tab. In that way, note that the program sleeps for 0.2 seconds after each data is sent from the board to the console and to the IoT tab. Next, note that the freeboard datasource has the parameter refresh every 0.1 seconds. This gives freeboard time to consume data faster than it arrives. If these values are mismatched, you may have strange delays on the IoT tab visualization.
Finally, note that all data has been transferred and plotted using the USB cable. You can take your board anywhere, open the BIPES program by URL, and plot the data right where you are, even without an Internet connection, as BIPES works offline.
By the way, we have been sharing BIPES programs here since the first example. So, if you want to share yours, simply click on the share button:
An Internet link will be generated with everything you created: block-based program, board definition, language, and IOT tab datasources and widgets.
BIPES EasyMQTT Bridge
Even without the board being connected to the Internet, BIPES offers a feature called EasyMQTT Bridge, which publishes the board’s data, received over USB, to the BIPES MQTT server. To do so, define a session (by clicking on the gear) and activate the “EasyMQTT Bridge” button on the Console tab:
When you click on the gear, you have the option of defining the EasyMQTT Session ID. Type one ID. Next, you can view the session. Click on “View EasyMQTT Session”, and you will have access to the link:
CircuitPython offers the nice feature of a file system based on the ESP32S2 flash memory, so we can add files with data, programs, and other contents. In the “normal” mode, the device is detected and used as a USB thumb drive. Files copied to the CIRCUITPY USB thumb drive are available for the CircuitPython environment using file operations calls, so your CircuitPython programs can use these files.
BIPES brings an additional way to manage files on the board: a file manager based on the browser that exchanges file commands to the board using a USB port (thanks to Web Serial API used by BIPES). Thus, BIPES can manage files on the Franzininho WiFi board with CircuitPython. Furthermore, BIPES also offers an editor in its own IDE in the web browser. Just use the Filestab. It is possible to upload files to the board, download files from the board, delete files, edit files through the text editor and run Python programs recorded in files on the board. As said, all these operations take place via USB.
Important: By default, the FLASH filesystem of CircuitPython is mounted read-only, as the board provides the CIRCUITYPY thumb drive.
BIPES will remount the filesystem on write mode with the command storage.remount(“/”, False). However, first, you must EJECT / SAFELY REMOVE / UMOUNT the CIRCUITPY USB Drive, so the BIPES file manager and your programs can write to files on the FLASH Memory.
After the filesystem is correctly mounted, you can go to the files tab and click on Refresh to update the file list:
And the file list will be updated on the left part of the screen:
Note that CircuitPython, by default, runs code.py automatically when the board boots. It is possible to click on this file, edit it, save and Run with the Run button, and, of course, it will run when the board boots.
Connecting to the Internet
You can use BIPES blocks to list available WiFi networks on the toolbox “Network and Internet“:
The result will give details about the available networks, like this:
We can also connect to the Internet:
And the result can be seen on the Console. For the example, the network selected is “Termometro”:
Web: HTTP Client
Once connected to the Internet, you can make HTTP GET requests. For example, we made the URL http://bipes.net.br/test.txt available for testing convenience. Here is an example that accesses this web page:
And the result would be similar to:
But we can use HTTP GET requests for dozens of powerful features using integration with other services using APIS. For example, we could check the weather using the OpenWeatherMap free web service and change the NeoPixel LED color according to the weather. Here is one possible program to do that:
To use the program, you must create an account on http://openweathermap.org/api and generate an API key. Then copy the generated API key and paste on YOUR KEY text on the block that defines the URL to be accessed.
Then we manipulate this response to get only the contents of “description”, which is “light rain”. There are several methods for this text parsing, so we present one simple and basic approach to this program.
The following image shows the result seen on the Console, step by step. The program first prints the complete response, then each step of the parsing process until the program gets the weather description: light rain. Next, we execute some conditional statements, checking if the description is light rain. If it is, we light the NeoPixel LED in blue color. If we have a storm, we light the red LED. You can adjust other variations, for sure!
The Franzininho WiFi board can be connected to a USB power bank and act as a weather indicator device:
Check more details and explanations on the BIPES Book here:
Run the program and use the Console to check if the server started and the IP you can connect to the webserver.
When you access this IP using a web browser, you get:
We can also create HTTP links and actions at our web server with BIPES by verifying the contents of the block requested page. The following example offers some options to control the NeoPixel LED color.
Using web request blocks (HTTP GET), we can publish sensor data to the BIPES MQTT server and create dashboards that can be easily shared for access from other devices, with responsive technology, for visualization on mobile phones, again, using freeboard.
To accomplish that, we can use an URL to publish data to the BIPES EasyMQTT Server. For example, considering session 5001 and topic Topic1, we can publish the value 1:
This QR-Code can be read by a smartphone, which will open the URL to show the dashboard with real-time updates:
BIPES offers several other options, including custom Python code inside blocks, creating functions, and much more. If you are new to BIPES, you can check out the BIPES book at https://bipes.net.br/wp/book-livro/. You can also learn more about BIPES at the project GitHub repository and interact at the BIPES discussion forum. Both are available at the link: https://github.com/BIPES/BIPES/.
Thanks for the interest in the BIPES project and in this text. Hope it’s been helpful for you.
Nossa intenção é revisitar os exemplos e instruções apresentados pelo Fábio e Diana através do BIPES (https://bipes.net.br/). Para seguir, a placa já deve possuir o CircuitPython instalado, conforme explicado pelo Fábio e Diana na documentação do Franzininho WiFi citada acima. Considerando o CircuitPython já instalado na placa, nenhum software ou configuração adicional precisam ser feitos. Basta acessar o BIPES e programar / controlar sua Franzininho WiFi. Recomenda-se o uso do Google Chrome.
O BIPES também permite plotar dados através de um dashboard IoT. Para isso, utilize o bloco “Show on IoT tab” e a aba IoT. Você pode usar este bloco várias vezes e plotar vários valores simultaneamente:
Mesmo sem a placa estar conectada na Internet, o BIPES oferece um recurso chamado EasyMQTT Bridge, que publica os dados da placa no servidor MQTT do BIPES. Para tanto, defina uma sessão (clicando na engrenagem) e ative o botão “EasyMQTT Bridge”:
Ao clicar no botão “View this EasyMQTT Session”, você terá acesso ao link:
Você pode usar o BIPES para gerenciar arquivos na placa Franzininho WiFi. Além disso, o BIPES também oferece um editor em sua própria IDE no navegador Web. Basta utilizar a guia Arquivos. A partir dela é possível enviar arquivos para a placa, baixar arquivos da placa, apagar arquivos, editar arquivos pelo editor de textos e executar programas Python gravados em arquivos na placa. Todas estas operações ocorrem via USB.
Nota: Como os arquivos da placa estão em um sistema de arquivos compartilhado com dispositivo de armazenamento em massa USB, é preciso ejetar o dispositivo de armazenamento USB do seu PC para que o BIPES consiga gravar arquivos na placa.
Utilize o botão refreh para atualizar os arquivos:
Conectando na Internet
Você pode usar blocos do BIPES para listar redes WiFi disponíveis a partir dos blocos disponíveis em “Rede e Internet”:
E também conectar na Internet:
O resultado pode ser visto no Console:
Cliente HTTP Web
Uma vez conectado na Internet, você pode fazer requisições HTTP, acessando sites ou serviços web (webservices). Por exemplo:
E é possível acompanhar as requisições pelo Console:
EasyMQTT e dashboard IoT
Utilizando os blocos de requisições web (HTTP GET), podemos publicar dados de sensores para o servidor MQTT do BIPES e criar dashboards que podem ser compartilhados facilmente para acesso a partir de outros dispositivos, inclusive com tecnologia responsiva, para visualização em celulares.
Para tanto, usaremos a URL de publicação de dados no servidor EasyMQTT. Exemplo:
Este QR-Code pode ser lido em um smartphone, possibilitando visualizar o dashboard:
Algumas implementações ainda são beta e podem oferecer bugs. Por exemplo, o servidor web e cliente web podem dar erro de “Out of Sockets”. Este bug está relacionado com o código do CircuitPython. Estamos trabalhando para reduzir estes bugs.
While teaching and giving hands-on workshops, it is not always easy to install and prepare esptool.py on some computers to flash MicroPython. So, we have adapted esp-web-tools (https://github.com/esphome/esp-web-tools) to flash MicroPython 1.7 on ESP32 and ESP8266 at the click of a web browser button (literally!).
Just connect your ESP32 or ESP8266 to the USB port and access:
This is a simple demo of BIPES and BBC micro:bit using BIPES with BIPES EasyMQTT bridge feature sending data to the BIPES IoT cloud and making it available for everyone on real time! Thanks for the micro:Bit Brasil community and Hackids for motivating this post!
First, install MicroPython on your BBC micro:bit board (simply copy the .hex file to the MICROBIT thumb drive):
But no problem just a few are supported. You can easily build your own blocks like I did:
Plot data using USB port
Note that the program listed above has the “Show data on IOT tab” block. This block “prints” data to the console and such data are routed to the IOT tab. There you can easily customize several types of gadgets for real-time data visualization using BIPES data source.
Click on IOT tab, and connect to the board. When the program is running you will automatically see the data being updated. This happens thanks to the BIPES-DATA messages sent from the board to the console:
Share data with the world!
Note that on the Console tab there is a “Bridge data to EasyMQTT” switch. When this switch is active, data received on the USB port are forwarded to BIPES EasyMQTT server and made available to anyone on the Internet. You can view the raw data on the EasyMQTT URL:
The shared link can be generated by clicking on the share button and will allow anyone, on any device to view data from your micro:bit on real time! The data goes from the micro:bit using USB to your browser, then to BIPES server and to the world!
Other Cool features
If you have Internet connection problems, you can download BIPES offline and use almost all BIPES features offline, without the need of any connection or without the need to install anything. Simple unzip the BIPES OFFLINE zip and click on index.html.
BIPES has a unique feature for boards with MicroPython, including micro:bit, which is a file manager on the web browser. It allows you to load programs and files on the board. You can also download and interactively edit files and MicroPython programs and click “Run” to test them. The code automatically generated by the blocks is also available for text mode editing. All the files are permanently stored on the board, so you can have multiple programs, select the one you want to run, create data log files, etc!
BIPES allows you to work simultaneously with multiple block-based programs. Click on the user button on the top right area on the screen and alternate between programs. This great feature has been implemented by Jorge.