Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    wlan.scan() not working on FiPy

    Scheduled Pinned Locked Moved Discussion
    12 Posts 4 Posters 743 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sandris
      last edited by sandris

      So I get wlan.scan() to work on Gpy, but when I try the same code on a FiPy (Legacy firmware, 1.20.0.rc13) I just get "OSERROR: Scan operation Failed!"

      Minimum failure example.

      from network import WLAN
      wlan = WLAN(mode=WLAN.STA)
      wlan.scan()
      

      Tried with wifi_on_boot set as both False and true, no change. Please advise on how to get passed this problem.

      O robert-hhR A 3 Replies Last reply Reply Quote 0
      • O Offline
        oligauc @sandris
        last edited by oligauc

        @sandris Can you do an erase from the Terminal / command prompt please and retry.

        pycom-fwtool-cli.exe -p 'your COM port' erase_all

        and re-flash

        1 Reply Last reply Reply Quote 0
        • S Offline
          sandris
          last edited by

          @oligauc said in wlan.scan() not working on FiPy:

          pycom-fwtool-cli.exe

          No luck. I've tried with two diffrent FiPys and both fail.

          1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @sandris
            last edited by

            @sandris said in wlan.scan() not working on FiPy:

            from network import WLAN
            wlan = WLAN(mode=WLAN.STA)
            wlan.scan():

            In this example the line wlan_scan() end with a colon. Since that is an syntax error, I assume that your actual code is different.

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              sandris @robert-hh
              last edited by

              @robert-hh

              Hi thx, just a little typo there yes.

              1 Reply Last reply Reply Quote 0
              • A Offline
                andreas @sandris
                last edited by

                Dear @sandris,

                @sandris said in wlan.scan() not working on FiPy:

                OSError: Scan operation Failed!

                Maybe try wlan.init() first. See also https://forum.pycom.io/topic/5258/firmware-release-v1-20-1/41.

                With kind regards,
                Andreas.

                robert-hhR 1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @andreas
                  last edited by

                  @andreas Calling the constructor WLAN(....) implies calling init. Calling both with different parameters is troublesome.

                  A 2 Replies Last reply Reply Quote 0
                  • A Offline
                    andreas @robert-hh
                    last edited by

                    @robert-hh Thanks for letting me know. I will try to optimize our datalogger codebase regarding this aspect.

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      andreas @robert-hh
                      last edited by

                      Dear Robert,

                      @robert-hh said in wlan.scan() not working on FiPy:

                      Calling the constructor WLAN(....) implies calling init. Calling both with different parameters is troublesome.

                      In order to get everything right, I've just investigated this very aspect. According to the lowlevel code at [1], I found that the WiFi peripheral is actually not initialized when the constructor is called without arguments.

                      In this case, .init() will do just that and so a two-stage approach feels sensible where there is room in between for setting up the details in a discrete, step-by-step manner as outlined within [2].

                      I.e., we want to configure the WiFi mode and whether an external antenna is connected or not based on individual configuration settings. Doing it that way, we will not have to get into spaghetti code having to call the constructor with different combinations of arguments.

                      Please let me know if I might have overlooked something here.

                      With kind regards,
                      Andreas.

                      [1] https://github.com/pycom/pycom-micropython-sigfox/blob/69dd8b5d/esp32/mods/modwlan.c#L1294-L1301
                      [2] https://github.com/hiveeyes/hiveeyes-micropython-firmware/blob/4cf2c516/terkin/network/wifi.py#L82-L111

                      robert-hhR 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @andreas
                        last edited by

                        @andreas Yes and not. You can use the constructor to set all init parameters, and you can do that in the init call. What fails is an attempt to split the configuration up between calling the constructor and calling init(). Because init will use it's default values for all parameters not set.
                        Saying that, I did not look into the code again. I'm just assuming the usual coding practice in MicroPython.

                        A 1 Reply Last reply Reply Quote 0
                        • A Offline
                          andreas @robert-hh
                          last edited by

                          @robert-hh said in wlan.scan() not working on FiPy:

                          Yes and not. You can use the constructor to set all init parameters, and you can do that in the init call. What fails is an attempt to split the configuration up between calling the constructor and calling init().

                          I would second that. I just had a look under the hood and wanted to share the pointer to the code and my findings back with you.

                          The reason why I've investigated this again is that we still experience WiFi connection problems on the very first attempt after a hard reset. This is deterministic for us on a FiPy sitting on an expansion board on our workbench.

                          Invoking .connect() twice with a short delay in between makes things work. While this feels weird, we haven't been able to find a different workaround.

                          robert-hhR 1 Reply Last reply Reply Quote 0
                          • robert-hhR Offline
                            robert-hh @andreas
                            last edited by

                            @andreas The typical structure you'll find in most MicroPythos-APIs for hardware devices is:

                            • there is a xxx_make_new (in this case wlan_make_new(), line 1279, mods/modwlan.c), which is called when the constructor in python is called. This function shows all the init arguments with its default values. It calls xxx_init_helper().
                            • there is a xxx_init (in this case wlan_init(), line 1305, which more or less only calls xxx_init_helper().
                            • and finally there is xxx_init_helper (here wlan_init_helper(), line 1145, which actually scans the supplied parameters and sets up the device. Parameters which are not supplied are set to the default values.
                            1 Reply Last reply Reply Quote 0

                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                            With your input, this post could be even better 💗

                            Register Login
                            • 1 / 1
                            • First post
                              Last post

                            Pycom on Twitter

                            Pycom