Importing & using external libraries



  • Hello,

    I'm new to Python (having C/C++ and C# background).

    I'm trying to use the MQTT library https://pypi.python.org/pypi/micropython-umqtt.simple

    import umqtt

    works

    but

    from umqtt import MQTTClient

    gives:
    ImportError: cannot import name MQTTClient

    What am I doing wrong?

    Thanks.



  • @bucknall Thanks.
    Using the MicroPython Interpreter
    I use the built-in serial terminal on Mac OS known as 'screen' to open a USB serial connection to the Pycom Device.

    Maybe a stupid question, but why do you serial connect to the xxPy (using eg screen on Mac, the alternative on win I suppose is Putty or TeraTerm)? Pymakr itself has already a serial connection the xxPy? Additionally isn't writing your code as part of a project (in Pymakr) followed by ftp'ing (FileZilla or other) the code/firmware from the Mac or win PC to the xxPy not enough?

    Also, when clicking (in Pymakr) "Run this code' what exactly happens, isn't clear to me? Should I first ftp the code to the xxPy and then click "Run this code", but if so I'm asking myself why, because when you reset the xxPy the code/firmware runs from the xxPy?

    Thanks.
    Guy



  • @gdillen We're aware of some of the issues on-going with Pymakr so for the mean time, we're recommending people utilise a slightly different workflow which will be streamlined when our plugins arrive either next month or the following. We believe there are currently some file corruption issues happening with Pymakr.

    I have two processes I use for development cycle:

    1. Using the MicroPython Interpreter

    I use the built-in serial terminal on Mac OS known as 'screen' to open a USB serial connection to the Pycom Device.

    $ screen /dev/cu.usbserial-*your device* 115200
    

    If the board is connected to your computer it should open up into the REPL, you may need to press ctrl-c to escape a program if there is one running.

    Let me know if you're using Windows I'll suggest an alternative!

    1. Uploading my code to the board using Filezilla (FTP)

    Once I've written my code (I use the Atom editor) and I'm happy with a project, I'll upload it to my device using Filezilla (FTP).

    I place my library files into the 'flash/lib' folder and the rest or my code, boot.py & main.py into 'flash/'.

    You should ensure that you've set Filezilla up in a configuration specified in the link below as there are some slight tweaks to be made!

    https://docs.pycom.io/pycom_esp32/pycom_esp32/toolsandfeatures.html#filezilla-settings



  • @bucknall Thanks. I run Firmware 1.6.7.b1.

    I probably don't understand fully the "development life cycle".

    • On one of my LoPy's I created a test project (connecting/sending LoRaWAN messages) using Pymakr, run main.py and it worked (on this LoPy I didn't any sync in Pymakr or connected using FileZilla to transfer anything)
    • On my other LoPy I created a project in Pymakr and transfered the local (on my laptop/Mac) to the LoPy
      As you can imagine I'm confused as of what's the correct way to develop and deploy on the xxPy? Can you please explain in few words?
      Probably the library problem I have has to do with this?

    By the way running sync in pymakr always results in "failed".

    Thanks for your help.
    Guy



  • Hi @gdillen,

    Are you using the latest version of the Firmware? If so it might be worth a quick update as this may resolve any of the issues you're having!

    What are you using to upload your libraries to your LoPy? Let me know and I'll try my best to get you up and running!

    Thanks,

    Alex



  • I've got it to work on 1 LoPy but using the exact same code on another LoPy still gives the same problem!
    Probably I'm still doing something wrong, I don't know?!

    So my first impressions:
    I did embedded development for several years in C/C++ without any major problems. So I thought (advertising faster development, etc.) let me start also trying doing some development with a LoPy but I really get frustrated, continuously having problems, ... To me at the contrary I'm losing days in development ... and probably go back to (stable) C/C++ embedded development.


Log in to reply
 

Pycom on Twitter