Tag Archives: esp8266

Micropython – Development tools Ampy – Eric

After the  uPyCraft  intallation in the previous article

MicroPython – IDE MicroPython uPyCraft

let’s now look at other tools available for the development in MicroPython for various platforms.

This article shows the operations to be performed on Windows and Linux.

First Python package to install is Ampy (Adafruit MicroPython Tool)

ampy

The tool is available in the python repositories, so it can be installed using the  pip tool.

In Windos run in a dos command prompt

Similarly in Linux run in a shell

The available commands are listed running

ampyAmpy allows the transfer, creation, viewing, and execution of files on the device.

As for the IDE you can install Eric, generic Python IDE

Eric

Eric does not allow communication from the IDE with the device as seen with uPyCraft; this task is delegated to Ampy. For the installation proceed as follows:

  • For Linux Debian 9 just run

The tool is available among the development tools; at the first execution it requires default settings

ericSettingsWe define the workspace location

ericWorkspaceand we have the access to the IDE

eric

  • For Windows download the zip

Eric

Unzip the zip into a folder from which we run it; install the prerequisites

Perform the eric installation at this point by double clicking on install.py

ericInstallWindowsThe program checks the prerequisites and completes the installation

ericWindowsProcedure

Clicking twice on eric6.py or running eric6 from a dos command prompt we run the program in the same way as seen for Linux Debian

ericWindows

In the next article we will briefly examine how a MicroPython program is structured

MicroPython – MicroPython program structure

 

Micropython – MicroPython IDE uPyCraft

After installing the firmware on the Nodemcu esp8266 DevKit board

MicroPython Firmware

let us now examine a development tool can be suitable for the development of Python code.

A tool that allows both to write code and upload it to the device is uPyCraft

uPyCraft

The tool currently works for Windows and from version 0.30 is also available for Linux; the source code is available at the link

uPyCraft Source

Here are the steps for Windows and Linux.

  • Windows

Once downloaded the package we must  run it as an administrator; the installation of the Monaco font is required

monaco-font

After the font installation,  we have the access to the IDE

upycraft-v0-29We set the Location in Tools->Preferences->Language Location

upycraftlocation

and the serial port paramenters in Tools->Preferences->Serial

upycraftserialsettingsWe plug the device into an USB port and set the serial port on uPyCraft

upycraftserialWe choose the device type; in this case it is ESP8266

upycraftdeviceBy clicking on the connection icon we access to the device and view the files on it

upycraftconnectionThe firmware installation expands on the device only the Python file boot.py

upycraftfilesystemThe tool allows to download examples of MicroPython code for the board, blink.py for example

examplesClicking the “Download and Run” button we load the code onto the device and run it

blinkIn this example the led of the Nodemcu DevKit blinks.

  • Linux

The tool is similar in the Linux version; once downloaded the package to which we have to assign  the execution right we run it. We must assign to the user the access to the serial port with the command, already seen above

In our case, on Debian 9, we have the following screens similar to what we saw on Windows.

In the uPyCraft IDE

upycraft-v0-30linuxWe set the Location in Tools->Preferences->Language Location

upycraftlocationlinux

and the serial port paramenters in Tools->Preferences->Serial

upycraftserialsettingslinuxWe plug the device into an USB port and set the serial port on uPyCraft

upycraftseriallinuxWe choose the device type; in this case it is ESP8266

upycraftdevicelinuxBy clicking on the connection icon we access to the device and view the files on it

upycraftconnectionlinuxThe firmware installation expands on the device only the Python file boot.py

upycraftfilesystemlinuxThe tool allows to download examples of MicroPython code for the board, blink.py for example

exampleslinuxClicking the “Download and Run” button we load the code onto the device and run it

blinklinuxAs in Windows the led of the Nodemcu DevKit blinks..

In version 0.30 for Windows we noticed some bugs, so for this operating system we continue to use the uPyCraft  version 0.29.

Further informations about uPyCraft can be found at the following site

uPyCraft Documentation

In the next article we will discuss another Python development tool

MicroPython – Development tools Ampy – Eric

MicroPython – Python on embedded devices

In this article we begin to treat MicroPython

MicroPython

an implementation of Python3

Python

for embedded devices.

Various images are available on the MicroPython website for different devices, including the modules esp8266 and esp32

MicroPython Dowloads

We start our tests with a Nodemcu esp8266 DevKit

Nodemcu Devkit

We proceed to load the firmware  on this card.

The Micropython site also refers how to load the firmware on the cards; these informations are available at the link

MicroPython Tutorial for esp8266

To load the firmware we always use the tool esptool, also available on the Python repository.

To be able to use it, we need to install Python3 on our development platform. Here are the steps to follow for Windows and Linux.

  • Windows

For windows we must first install the Python3 environment, available at the following link

Python for Windows

In our case, we downloaded the  version 3.6.4 for 64-bit systems. We installed the package  with administrative rights

setuppythonAfter proceeding to add Python in the Path we click “Install Now”

pythonsetupendAfter the installation, we open a dos command propmt and check the installed Python version

pythonversionAlways from the dos command prompt we proceed to the installation of esptool with the command

esptoolinstallationAt this point we can proceed to the MicroPython firmware upload on the Nodemcu esp8266 DevKit. Of course, it is necessary to have the serial-ttl drivers installed for your DevKit model on Windows. Now go into  the folder where the firmware has been downloaded  and run the following  commands from the dos command prompt

erase_flashProceed to load the firmware

firmware_flashOnce the firmware is installed  we log on the Python console using, in our case with the nodemcu card DevKit, the same port already used to load the firmware.

On Windows we can use Putty

Putty

and set the serial connection to 115200 baud rates

repl_putty

  • Linux

For Linux we use the Debian 9 distribution, but the procedure can be extended to other distributions. After installing Debian 9 , similar to version 8

Debian 8

we proceed to the installation of Python3 and esptool from a Linux shell

Add the user used on Debian to the dialout group

In our case, using  sviluppo as a user, the command is as follows

Let’s move on to install the Python esptool package

We can then proceed with the installation of the firmware in the same way as done on Windows.

We check on which serial port the card is available (ttyUSBX)

ttylinuxWe perform a flash erase and firmware upload

To log on the DevKit we use screen

Here is the manual of the tool

Screen Manual

To detach from screen press

instead to resume run

To quit screen

Once connected you get the same result as Windows

screenIn the next article we will begin to see which IDEs can be used to create and load our Python code

MicroPython IDE uPyCraft

 

Mqtt with Beaglebone and ESP8266 – Articles List

Below is a list of the  articles to follow  to build your IOT environment consisting of sensors and relays with Beaglebone, ESP8266 and MQTT Mosquitto server.

  1. Architecture and Mqtt protocol
  2. Mosquitto Mqtt installation on Beaglebone
  3. Mqtt on ESP8266
  4. Temperature sensor on ESP8266 with Mqtt protocol
  5. Relay on ESP8266 with Mqtt protocol
  6. Configuration of Http server, Mqtt websocket protocol on Beaglebone
  7. Freeboard dashboard installation and configuration on Beaglebone
  8. Android client to manage sensors with Mqtt protocol

Mqtt with Beaglebone and ESP8266 – Android Client

After Mosquitto server, ESP8266 nodes and Freeboard configuration

Mqtt with Beaglebone and ESP8266-Mosquitto installation on Beaglebone

MQTT with BeagleBone and ESP8266-MQTT ESP8266

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with Relay

Mqtt with Beaglebone and ESP8266 – Freeboard

now we can proceed to use a Mqtt Client on an Android device.

In the Playstore various Mqtt applications are available

android mqttAfter the publishing and subscriber topics configuration in the Android client , analogous to what has been done for Freeboard widgets

Mqtt with Beaglebone and ESP8266 – Freeboard

it is possible to monitor the sensor temperature and humidity, the devices status and send commands to the relay (Turn On, Turn Off, Status, Restart, Sleep) and to the sensor (Restart, Sleep, Status).

Here is a screenshot with some subcriber topic and publisher topics of our installation using MQTT Dashboard

android mqtt relayoffWith the relay on

android mqtt relayon

Mqtt with Beaglebone and ESP8266 – Freeboard

After the Mqtt web client installation

MQTT with Beaglebone and ESP8266 – WebServer and MQTT WebSocket

let’s install now the dashboard freeboard

Freeboard

In a ssh commad shell go into the /var/www/html  folder on Beaglebone as root and clone the freeboard github respository; change the owner of the freeboard folder in www-data:www-data

With a web browser go to the freeboard  folder on Beaglebone webserver to access the dashboard

freeboard

We have to add now Freeboard additional plugins. We add the following

  •  freeboard-mqtt

Clone the https://github.com/alsm/freeboard-mqtt github

Download the mqtt paho javascript library

Paho mqtt javascript library

Here is the direct link to the library

Last Version mqttws31.js

Create the mqtt folder under the Freeboard plugins folder and copy the mqttws31.js and paho.mqtt.plugin.js files

Edit the paho.mqtt.plugin.js file and insert the reference to the mqttws31.js library in the external_scripts section; in this case too we have to change the folder and contents owner

Change the owner

Edit the /var/www/html/freeboard/index.html file and insert the reference to the paho.mqtt.plugin.js plugin in the heads.js section

  • Add the dynamic-highcharts plugin

Clone in a folder the github

Copy the plugin_highcharts.js to the folder /var/www/html/plugins/thirdparty and change the owner

Edit again the file /var/www/html/freeboard/index.html and add the plugin as done above

Access now the Freeboard dashboard and add the links to the temperature and humidity topics, the gauges and timeseries mesauring the values in real time and in a specific range of time . Here are some settings:

  • Datasource

freeboard datasource

  • Gauge

freeboard gauge

  • Timeseries

freeboard timeseriesChrome/Chromium browser allows to save the settings in a json file. This settings can be loaded locally or loaded from the web server, saving for example the dashboard.json file in /var/www/html/freeboard,  with the url

The image shows the Freeboad interface with various widgets showing the status and timeseries of the ESP8266 relay and sensors

freeboard dashboard

In these series of articles we configured the envinronment to access the Beaglebone using the beaglebone.local/beaglebone alias

Debian sd card setup for Beaglebone Black

but you can use anyway the Beaglebone IP tho access the services provided by the board.

In the next article we’ll treat the Mqtt Android client

Mqtt with Beaglebone and ESP8266 – Android Client

 

 

 

MQTT with BeagleBone and ESP8266 – WebServer and MQTT WebSocket

After the MQTT server and  ESP8266 nodes configurations

MQTT with BeagleBone and ESP8266 – Mosquitto installation on Beaglebone

MQTT with BeagleBone and ESP8266-MQTT ESP8266

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with Relay

we analize now the webserver configuration on BeagleBone and  the Websocket configuration for the broker MQTT mosquitto always on Beaglebone.

First step is to access on the Beaglebone in ssh and disable the following services

Go into the folder /etc/apache2/sites-enabled and modfy 000-default.conf  changing the webserver port from 8080 to 80

In /etc/apache2/port.conf modify the listening port from  8080  to 80

Restart the Http server

Go into folder  /etc/mosquitto/conf.d and create a new file websockets.conf with the following contents inside

Save the file and restart Mosquitto

Disable the IPV6 protocol on  Beaglebone as described at the following link

Disable IPV6 in Debian

In the file /etc/sysctl.conf add

Restart the Beaglebone.

We proceed at this point to install on the http server a MQTT Websocket client and the Freeboard dashboard.

As for the MQTT Websocket client hive-MQTT we download the code from github

Hive mqtt

Log in as root in ssh on Beaglebone and go into /var/www/html folder;  clone the Mqtt client into mqtt-web folder and change the owner of this folder

With a web browser navigate on our Http server to the mqtt-web link obtaining the Mqtt Web client; we can now set the parameters for the connection to the Mosquitto Mqtt Broker

mqtt web client connectionPopulating the values for the subscription and publishing topics we can access to the messages of the topics and the ability to perform a command to the publishing topic

mqtt web clientIn the next article we’ll install the Freeboad dashboard on the Beaglebone

Mqtt with Beaglebone and ESP8266 – Freeboard

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with Relay

After the article about the connection with the temperature and humidity sensor

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

in this article we set the esp8266 to run a relay. Here is how we connect the relay to the ESP module

nodemcu relay

In this example too we will consider the option of putting the nodemcu in sleep. To have the node back form the sleep the system has to reboot and  it is necessary to connect the PIN D0 (GPIO16) to RST PIN as specified in the nodemcu documentation

Nodemcu sleep

Let us take a look at the lua code; It consists of init.lua and relay.lua files.

We analyze now the main points of each file

  • init.lua

In the file we set the the parameters to access the wifi network, the address and port of the MQTT broker  and the file to be run on the ESP after wifi connection to the access point is estabilished. If the ESP doesn’t acquire the network address the system is restarted.

  • relay.lua

The relay.lua file manages the relay, the subscription on MQTT broker with submission of the data. Global parameters have been set to manage the topic, the waiting time in tmr.alarm. There are in particular the following topics

  • /home/relay1/status : Status topic. The status is sent at the start and at  request from the command topic /home/relay1/command.
  • /home/relay1/monitor: Status of the esp sent periodically to this topic.
  • /home/relay1/command: Other clients can send commands to the esp:
    • Restart: Restarts the esp.
    • Sleep n: Put to sleep for n seconds the esp.
    • ON: Turn on the  relay.
    • OFF: Turn off the  relay.
    • Status: Request of tthe relay status (ON or OFF).

There are various service functions to manage all. The comments in the code describe each feature.

In the next article we will set up the webserver on Beaglebone and the websocket configuration for Mosquitto always on the Beaglebone

MQTT with BeagleBone and ESP8266 – WebServer and MQTT WebSocket

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

After loading the firmware into the device esp8266

MQTT with BeagleBone and ESP8266-MQTT ESP8266

we now connect this module with a DHT11 temperature and humidity sensor. Here is how we connect the sensor to the ESP module

nodemcu dht11

In this example we will consider the option of putting the nodemcu in sleep. To have the node back form the sleep  the system has to reboot and  it is necessary to connect the PIN D0 (GPIO16) to RST PIN as specified in the nodemcu documentation

Nodemcu sleep

Let us take a look at the lua code; It consists of init.lua and tempumid.lua files.

We analyze now the main points of each file

  • init.lua

In the file we set the the parameters to access the wifi network, the address and port of the MQTT broker  and the file to be run on the ESP after wifi connection to the access point is estabilished. If the ESP does’t acquire the netowrk address the system is restarted.

  • tempumid.lua

The temumid.lua file manages the measurement of temperature and humidity, the subscription on MQTT broker with submission of the data. Global parameters have been set to manage the topic, the waiting time in tmr.alarm. There are in particular the following topics

  • /home/room1/temperature: measured temperature topic.
  • /home/room1/humidity: measured humidity topic.
  • /home/room1/status : Status topic. The status is sent at the start and at  request from the command topic /home/room1/command.
  • /home/room1/monitor: Status of the esp sent periodically to this topic.
  • /home/room1/command: Other clients can send commands to the esp:
    • Restart: Restarts the esp.
    • Sleep n: Put to sleep for n seconds the esp.

There are various service functions to manage all. The comments in the code describe each feature.

In the next article we will set up the esp with the relay

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with Relay

 

Mqtt with Beaglebone and ESP8266-MQTT ESP8266

After installing the MQTT server on BeagleBone

Mqtt with Beaglebone and ESP8266-Mosquitto installation on Beaglebone

let us set the MQTT nodes on ESP8266.

As first operation we must generate the nodemcu firmware, as described in the previous article

Nodemcu compilation on Linux

with at least the following parameters activated in user_module.h file

  • DHT
  • file
  • GPIO
  • MQTT
  • net
  • node
  • timer
  • UART
  • WiFi

These settings are the default in the user_module.h file.

At present the latest version 2.0 of nomemcu firmware was released. Here are the compiled files for this version of the firmware

Nodemcu2.0.0 firmware

As already described in previous articles and from the nodecmu link on flashing

Flashing the firmware

 we have to set the correct parameters for  the  esp8266 model.

In our case, with 4MB flash, we used the parameters shown in the image to load the firmware on the device with nodemcu-flasher tool. You can also use other tools for loading the firmware. In our case, the settings used are as follows

nodemcu flasherIn the next article we’ll treat the ESP8266 node that detects temperature and humidity

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor