and insert at the beginning of the “Compiler command pattern” xtensa-esp32-elf-

Save the configurations.

The project settings should always be made by make menuconfig in the unix shell.Access the shell and set the LED to be switched on/off the value 2 as GPIO;this is because in our case the card is a doit whose design is illustrated in this document

we now show how build a module inside the firmware; this option optimizes the module execution and minimizes the size of the same on the device; the module is frozen into the firmware.

With the firmware compiled with the defaults, the following modules are available, listed in the REPL console with the command

1

help('modules')

Now let’s try to compile the firmware with the mqtt modules already inside.For this purpose, the module sources are copied to the umqtt folder under modules

1

2

micropython/ports/esp8266/modules/umqtt/simple.py

micropython/ports/esp8266/modules/umqtt/robust.py

We proceed to recompile the firmware.From micropython/ports/esp8266 we run the following commands

1

2

make clean

make

We can see from the compilation log, that these modules are placed in the frozen state

After uploading this firmware we obtain the following list of modules inside the firmware

It is also possible to create the firmware with the modules not compiled and optimized, by copying the sources in the scripts folder under esp8266;in the specific case the sources must be placed as shown below

1

2

micropython/ports/esp8266/scripts/umqtt/simple.py

micropython/ports/esp8266/scripts/umqtt/robust.py

The modules are always visible in the firmware, but not optimized, so if you need some module it is convenient to copy it on the device during the coding and in the last phase of the project compile the firmware with the frozen modules.

In the following examples, only the umqtt simple is used; in the code several delays have been inserted to allow the board to manage the messages and not run into errors;in the case the Mqtt server is not available the code restarts the board.

Below the code used for these examples.

Node with DHT11 sensor

boot.py: code executed at startup

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

#This file is executed on every boot (including wake-boot from deepsleep)

The additional modules can be downloaded from the link of the libraries presented above or downloaded with the upip utility (Package Manager) from the REPL console if available in the Python Package Index (PyPI) repository

Below is a simple example that connects to the router and allows us to access the MicroPython console with the browser and WEBREPL.

boot.py code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

#This file is executed on every boot (including wake-boot from deepsleep)

import esp

#esp.osdebug(None)

#Connects to the wifi AP providing a hostname, AP Name and passord

def do_connect():

import network

sta_if=network.WLAN(network.STA_IF)

ifnotsta_if.isconnected():

print('connecting to network...')

sta_if.active(True)

#Sets the device hostname

sta_if.config(dhcp_hostname='ESP_TEST')

print(sta_if.config('dhcp_hostname'))

#CHANGE THE VALUES TO YOUR ACCESSPOINT NAME AND PASSWORD

sta_if.connect('ACCESSPOINT','PASSWORDACCESSPOINT')

whilenotsta_if.isconnected():

pass

print('network config:',sta_if.ifconfig())

#Imports various modules for network, webrepl and garbage collector

import gc

import webrepl

import network

do_connect()

webrepl.start()

gc.collect()

At the first access it is required to enable webrepl to be executed in the REPL console with the command

1

import webrepl_setup

we can activate the service and the access password.

The procedure generates the webrepl_cfg.py file on the device.

After setting up and restarting, we access the web console by opening the locally cloned webrepl.html file with a browser

Pressing connect and after entering the password ,set in the initial setup, we access the console

Now we install from the WEBREPL console, for example, the stat module using upip

1

2

import upip

upip.install("micropython-stat")

To paste commands execute Ctrl+A e Ctrl+V

In this case the package was taken from the PYPI repository, unpacked and installed on the device.

We have noticed that some modules, although available on the repository, give an error during installation with upip; these modules are installed directly without using the upip utility,but by downloading the library from the site listed above and transferring the code to the device.

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

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

We set the Location in Tools->Preferences->Language Location

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

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

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

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

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

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

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

In 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

1

sudo usermod-a-Gdialout USER

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

In the uPyCraft IDE

We set the Location in Tools->Preferences->Language Location

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

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

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

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

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

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

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

As 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