MicroPython on ESP32 with SPIRAM support

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sat Dec 23, 2017 11:15 pm

Ok that helped and but now it says

Your display is too small to run Menconfig!
It must be at least
19 lines by 80 colums

I can't find where in virtual box to give me bigger display

Edit after lots of googling I have found way to make fullscreen virtual box and now BUILD menuconfig works perfectly :)

Much thanks for your patience with my many questions

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sun Dec 24, 2017 12:20 am

Ok I ran ./BUILD.sh menuconfig and created the config file.

I then ran ./BUILD.sh but got the error message
'make all' FAILED!

EasyRider
Posts: 94
Joined: Wed Dec 30, 2015 8:17 am

Re: MicroPython on ESP32 with SPIRAM support

Post by EasyRider » Sun Dec 24, 2017 10:31 am

Hello Boris,

Sorry to pester you on Christmas eve, but its a good free time to play with micropython.

I have started playing with various micropython mqtt options on the esp32.

I'm having difficulty in understanding your version of API call for establishing a connection with a local wifi network mosquitto server broker.

At the moment everything's non secure, without passwords for simplicity.

Broker is a local SBA running mosquitto on OpenWrt linux on the same local unsecured wifi network, it works ok with standard micropython simple.py mqtt client example where only client id string and host/broker IP address are only 2 arguments required to connect.

If you have a bit of time please explain the API connection arguments in your mqtt example and provide a simple connection example to broker on local unsecured wifi network.
mqtt = network.mqtt("loboris", "loboris.eu", user="wifimcu", password="wifimculobo", cleansession=True, connected_cb=conncb, disconnected_cb=disconncb, subscribed_cb=subscb, published_cb=pubcb, data_cb=datacb)
Thanks

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sun Dec 24, 2017 12:35 pm

EasyRider wrote:
Sun Dec 24, 2017 10:31 am
If you have a bit of time please explain the API connection arguments in your mqtt example and provide a simple connection example to broker on local unsecured wifi network.
You can use mqtt_example.py for connection to broker on local network, just change "loboris.eu" to broker's IP address.
The complete documentation for all modules, including mqtt wil be pushed with the "New Year" update next week.

mqtt runs in separate thread (FreeRTOS task).
Note: When using secure connection more memory is required. If not using psRAM, you may need to lower the MicroPython heap.

Here is the simplified description of available mqtt methods:

Code: Select all

mqtt = network.mqtt(name, server [, user, password, port, autoreconnect, clientid, cleansession, keepalive, qos, retain, secure, connected_cb, disconnected_cb, subscribed_cb, unsubscribed_cb, published_cb, data_cb])
Creates the mqtt object and starts the mqtt client task.
Only two first arguments are mandatory:
  • name - string, mqtt identifier, used to identify the mqtt client object, for example in collback functions
  • server - string, mqtt server (broker) ip address or domain name
Other arguments are optional, if entered they must be entered as kw arguments (arg=value):
  • user - string, user name if requred by mqtt server, default: ""
  • password - string, user password if requred by mqtt server, default: ""
  • clientid - string, mqtt client id, it is recomended to enter some unique ID, default: "mpy_mqtt_client"
  • secure - bool, if True, use secure connection, default: False
  • port - int, server's mqtt port, default: 1883 if secure=False, 8883 if secure=True
  • autoreconnect - bool, if True, reconnect to server if disconnected for some reason, default: False
  • cleansession - bool, if True, do not use mqtt persistent session feature, default: False
  • keepalive - int, Keep Alive interval in seconds, default: 120
  • qos - int, mqtt QoS level, default: 0
  • retain - bool, mqtt retain flag, default 0
  • connected_cb - callback function executed when mqtt is connected to the server; arguments: mqtt_name
  • disconnected_cb - callback function executed when mqtt is disconnected to the server; arguments: mqtt_name
  • subscribed_cb - callback function executed on succesful topic subscription; arguments: (mqtt_name, topic)
  • unsubscribed_cb - callback function executed when the topic is unsubscribed; arguments: (mqtt_name, topic)
  • published_cb - callback function executed when the topic is published; arguments: (mqtt_name, publish_result)
  • data_cb - callback function executed when new subscribed topic data arrives; arguments: (mqtt_name, topic_data_length, topic_data)

Code: Select all

mqtt.config([clientid, autoreconnect, cleansession, keepalive, qos, retain, secure, connected_cb, disconnected_cb, subscribed_cb, unsubscribed_cb, published_cb, data_cb])
Reconfigure the mqtt client object.
All arguments are optional, if entered they must be entered as kw arguments (arg=value):

Code: Select all

mqtt.status()
Returns the status of mqtt client task.
The status is returned as tuple: (num_stat, description).
Possible values are:
(0, "Connected")
(1, "Disconnected")
(2, "Stopping")
(3, "Stopped")
Before issuing any other mqtt command always check the mqtt status.

Code: Select all

mqtt.subscribe(topic)
Subscribe to the topic, wait max 2 seconds.
Argument topic is string, topic name.
Returns True is successfully subscribed, False if not.

Code: Select all

mqtt.unsubscribe(topic)
Unsubscribe from the topic, wait max 2 seconds.
Argument topic is string, topic name.
Returns True is successfully subscribed, False if not.

Code: Select all

mqtt.publish(topic, msg)
Publish message to the topic.
Argument topic is string, topic name; msg is string, topic message
Returns True is successfully published, False if not.

Code: Select all

mqtt.stop()
Stop the mqtt client task. Used resources are freed.
Returns True on success, False on error.

Code: Select all

mqtt.start()
Start the stopped mqtt client task.

Code: Select all

mqtt.free()
Stop the mqtt client task. Free resources and destroy the mqtt object
Returns True on success, False on error.

EasyRider
Posts: 94
Joined: Wed Dec 30, 2015 8:17 am

Re: MicroPython on ESP32 with SPIRAM support

Post by EasyRider » Sun Dec 24, 2017 1:28 pm

Thanks Borislav for detailed explanation.

I have it working with clarified mandatory name and server arguments.

Will continue experimenting with other options.

Best Regards

carsten
Posts: 15
Joined: Wed Aug 16, 2017 3:08 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by carsten » Sun Dec 24, 2017 3:05 pm

Hi,

so right now I cant get uasyncio working with your firmware... I'll look into it in detail when I have time, but maybe you've already come across this:

>>> loop.run_forever()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "uasyncio/core.py", line 138, in run_forever
File "uasyncio/core.py", line 107, in run_forever
AttributeError: 'generator' object has no attribute 'pend_throw'

Happens when there is a yield asyncio.IORead(mysocket) in the code...

Edit: Ah, I see, pend_throw() is a Micropython addition to generators...
Edit 2: Patching https://github.com/micropython/micropyt ... 73f4bc42be works...
mysocket.setblocking(False)
packet, address = mysocket.recvfrom(256)
throws
OSError: [Errno 110] ETIMEDOUT
however...

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sun Dec 24, 2017 7:48 pm

@carsten

Have you tried to use threads instead of uasyncio ?
I would be interested if you can give me some example application where uasyncio is better suited then threads.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sun Dec 24, 2017 8:03 pm

When I run ./BUILD.SH I get the error

'make all' FAILED!

What am I doing wrong??

Merry Christmas to everyone :)

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: MicroPython on ESP32 with SPIRAM support

Post by loboris » Sun Dec 24, 2017 8:14 pm

@OutoftheBOTS_

Run:

Code: Select all

./BUILD.sh all verbose
That way the error messages will be visible, if any, please post them.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: MicroPython on ESP32 with SPIRAM support

Post by OutoftheBOTS_ » Sun Dec 24, 2017 9:07 pm

Ok Virtual box won't let me cut from inside the VM and paste outside so I have to type then out

this seems to were it started to go wrong

/home/bot/MicroPython_ESP32_psRAM_LoBo/Tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: Syntax error: ";" unexpected
make: *** [/home/bot/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD/phy_init_data.o] Error 2

Also I am using 32 bit Ubuntu as Virtual box won't run in 64 bit mode for me

Post Reply