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

    Unstable WiFi connection

    Scheduled Pinned Locked Moved LoPy
    lopy wifi
    7 Posts 3 Posters 511 Views 3 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.
    • A Offline
      Asb
      last edited by

      Hi

      I'm using a LoPy4 (same problem using a WiPy) that reads sensor data (using modbus), and publishes the sensor data to a private mqtt server. I'm also using threads using the _thread library. It works as expected, but after a short while (1-5 mins), the telnet repl connection drops and I get the following message: > Failed to connect ( Connection was reset). Click here to try again.
      I'm not able to connect via the telnet repl until 10-30s has passed ( > Connection error: Error: login timed out), during this downtime no mqtt messages are recieved by the mqtt server either. After the 10-30s I'm able to connect via telnet repl, and messages are recieved by the mqtt server.

      I have also tried connecting via USB, sensor data is read every 10th second and printed in the repl, however after a few minutes, the mqtt server stops recieveing messages (sensor data still printed in the repl). Then after a while the mqtt server starts recieveing messages again. Thus maybe indicating problems with the wifi connection.

      Have anyone else had similar problems, or could the usage of threads cause similar problems?

      Thanks.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Asb
        last edited by

        Update: Removed the thread, only publishing a dummy value via mqtt. Still having the same problems.

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          crumble @Asb
          last edited by

          @Asb

          Sounds like you use deepsleep or other stuff which reinit the WiFi connection. Sometimes the connection buildup needs some seconds at my home. Can't tell if it is the *Py or the router.

          I never had problems with telnet when the connection is established. But ftp hangs after a while and stops transfering data. But I was able to start another get/put immediatly.

          A 1 Reply Last reply Reply Quote 0
          • A Offline
            Asb @crumble
            last edited by

            @crumble Thanks, and sorry for the late reply.

            I am not using deepsleep, and I believe not any other stuff which reinit the WiFi connection either. Basically I'm using this code from pycom wlan docs: Multiple Networks using a Static IP Address in my boot file to connect to a WiFi network.

            And the stripped version of the main file contains:

            from umqtt.simple import MQTTClient
            
            client = MQTTClient("joe", "server ip", port=1883, user= auth['username'], password= auth['password'])
            client.connect()
            client.publish("/RFM/Test2", "Connected to: %s on %s" % (wl.ssid(),wl.ifconfig()[0]))
            
            while True:
                #sensor data, dummy values now
                result = [0, 123]
                try:
                    client.publish("/RFM/Test2", str(result))
                except:
                    print("Publish failed")
            
            1 Reply Last reply Reply Quote 0
            • T Offline
              timh
              last edited by

              You need to check the state of your mqtt connection, if it times out you probably are hung up on the socket, trying to write. Which means you loop is effectively stalled.

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                Asb @timh
                last edited by

                @timh Thanks, I will look into it.

                However (slightly off-topic), when I ctrl-c my program to upload changes/new files the upload sometimes fails and I have to manually reboot the device, this never happens if I use USB. Safe boot on upload is enabeled for both cases..

                C 1 Reply Last reply Reply Quote 0
                • C Offline
                  crumble @Asb
                  last edited by

                  @Asb said in Unstable WiFi connection:

                  this never happens if I use USB.

                  You have to try harder! Or you have simply more luck when using USB.

                  I noticed that this happens not very often, but when it happens a few times in short distance. So it may not be related to the kind of connection.

                  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