Detect board type or availble services?

  • Is it possible to detect what radios are avaible on the board? I have some code that i wish to auto-enable/disable code based on whether the board has sigfox,lora,lte- me? Is their a inbuilt variable that will indicate this"?

    File "", line 15, in <module>
    ImportError: cannot import name LoRa from a sipyboard, how do safely handle this?

  • @misterlisty Micropython uses the prefix u for its modules to indicate, that it may be a subset of what you have in CPython. For compatibility, the names without u are also provided. So, the genric name in MicroiPyhton is uos.uname, while os.uname is also possible. Likewise, you can write

    import uos
    import os

    There are some deviations from that simple rule. Like in CPython, you can use _io, whereas in Micropython it's called uio (not u_io), and _io is not known. Also, why some modules have a non-u alias and others not is unclear. You could change that easily in mpconfigport.h of the respective port.

  • @robert-hh Why do you use uos.uname() when i have to use os.uname(), even the doco refers to a presffix of u for some reason?

  • @misterlisty Python is an interpreting language, and Import statements get effective only when the statement is executed, unlike #includes of C. Simple test on a WiPy:

    import uos
    if uos.uname().sysname == "LoPy":
        from network import LoRa
        print ("not LoPy")

  • thanks but can i create conditional imports?

    if bLora:
    from network import LoRa #shuold this work?

  • @misterlisty You can use the output of uos.uname(), which returns a tuple with machine details. On a LoPy, uos.uname().sysname has the value "LoPy".

Pycom on Twitter