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

    Not getting Sensor Readings in Pysense with FiPy Module

    Scheduled Pinned Locked Moved MicroPython
    fipyraspberry pipysensemicorpython
    79 Posts 6 Posters 28.0k Views 6 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
      Archana Kadam @livius
      last edited by livius

      @livius

      from network import WLAN
      wlan = WLAN(mode=WLAN.STA)
      nets = wlan.scan()
      for net in nets:
          if net.ssid == 'mywifi':
              print('Network found!')
              wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
              while not wlan.isconnected():
                  machine.idle() # save power while waiting
              print('WLAN connection succeeded!')
              break
      

      Using above code we are getting the details of connected wifi. And we have different ip address.0_1520939453939_screnshot.PNG Here is the screenshot of our output please go through the image and update.
      Thank You

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @Archana Kadam
        last edited by

        @archana-kadam
        than you are connected to wifi - what more do you need?

        think about people first, then computers

        A 2 Replies Last reply Reply Quote 0
        • A Offline
          Archana Kadam @livius
          last edited by

          @livius
          How we can know that is connected to Wifi?
          How we can connect to both station as well as access point?

          L 1 Reply Last reply Reply Quote 0
          • A Offline
            Archana Kadam @livius
            last edited by

            @livius
            Please explain the procedure of connecting fipy to server and how to send data of fipy to server

            1 Reply Last reply Reply Quote 0
            • L Offline
              livius @Archana Kadam
              last edited by livius

              @archana-kadam said in Not getting Sensor Readings in Pysense with FiPy Module:

              How we can know that is connected to Wifi?

              wlan.isconnected()
              but to be really sure - only sending by socket tell this for sure

              How we can connect to both station as well as access point?

              change mode from WLAN.STA in WLAN.STA_AP

              Please explain the procedure of connecting fipy to server and how to send data of fipy to server

              simply create socket and send data throught it

              e.g. from memory not tested but something like this should work

              import socket
              s = socket.socket()
              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              s.connect(socket.getaddrinfo('your server ip', your_server_port)[0][-1])
              s.send(your_data)
              

              think about people first, then computers

              A 2 Replies Last reply Reply Quote 0
              • A Offline
                Archana Kadam @livius
                last edited by

                @livius
                Can we send data through pybytes ?
                Is a pybytes a server or its just a middleware to send data?

                A 1 Reply Last reply Reply Quote 0
                • A Offline
                  Archana Kadam @livius
                  last edited by

                  @livius
                  From this above code we are getting an error called OSERORR :-01
                  import socket
                  s = socket.socket()
                  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                  s.connect(socket.getaddrinfo('192.168.0.109', 80)[0][-1])
                  your_data = "Hello"
                  s.send("your_data")

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    livius @Archana Kadam
                    last edited by

                    @archana-kadam

                    From this above code we are getting an error called OSERORR :-01

                    At which line of code?

                    think about people first, then computers

                    A 1 Reply Last reply Reply Quote 0
                    • A Offline
                      Archana Kadam @livius
                      last edited by

                      @livius
                      Line number 6 and 7

                      L 1 Reply Last reply Reply Quote 0
                      • L Offline
                        livius @Archana Kadam
                        last edited by

                        @archana-kadam said in Not getting Sensor Readings in Pysense with FiPy Module:

                        Line number 6 and 7

                        I do not have your source code ;-)
                        what this lines contain? and why on 6 and 7 - error should be raised only once

                        think about people first, then computers

                        A 2 Replies Last reply Reply Quote 0
                        • A Offline
                          Archana Kadam @livius
                          last edited by

                          @livius
                          import socket

                          host = '127.0.0.1'
                          port = 80 # The same port as used by the server
                          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                          s.connect((host, port))
                          s.send('Hello, world')
                          data = s.recv(1024)
                          s.close()
                          print('Received', repr(data))
                          Here is code to connect to server,but we are enable to connect

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Archana Kadam @livius
                            last edited by

                            @livius
                            import machine
                            from network import WLAN

                            configure the WLAN subsystem in station mode (the default is AP)

                            wlan = WLAN(mode=WLAN.STA)

                            go for fixed IP settings (IP, Subnet, Gateway, DNS)

                            wlan.ifconfig(config=('192.168.0.107', '255.255.255.0', '192.168.0.1', '192.168.0.1'))
                            wlan.scan() # scan for available networks
                            wlan.connect(ssid='mynetwork', auth=(WLAN.WPA2, 'my_network_key'))
                            while not wlan.isconnected():
                            pass
                            print(wlan.ifconfig())
                            I tried with code also, but its continuously running but there no output.

                            L 1 Reply Last reply Reply Quote 0
                            • L Offline
                              livius @Archana Kadam
                              last edited by

                              @archana-kadam
                              I should start with this question, what is your firmware version?

                              import os
                              os.uname()
                              

                              think about people first, then computers

                              A 1 Reply Last reply Reply Quote 0
                              • A Offline
                                Archana Kadam @Archana Kadam
                                last edited by

                                @livius
                                Is Pybytes a server. Can we send data and store in pybytes

                                L 1 Reply Last reply Reply Quote 0
                                • A Offline
                                  Archana Kadam @livius
                                  last edited by

                                  @livius
                                  We have latest version of firmware installed 1.17.b

                                  1 Reply Last reply Reply Quote 0
                                  • L Offline
                                    livius @Archana Kadam
                                    last edited by

                                    @archana-kadam
                                    You can send data to whatever you like, but for pybytes you need account.
                                    Did you successfully connected to the wifi network?

                                    think about people first, then computers

                                    A 1 Reply Last reply Reply Quote 0
                                    • A Offline
                                      Archana Kadam @livius
                                      last edited by

                                      @livius
                                      We are running the below code on the FiPy to send data to the server. and we are using FiPy in its default mode i,e Access Point Mode.

                                      import socket
                                      s = socket.socket()
                                      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                                      s.connect(socket.getaddrinfo('192.168.0.109', 80)[0][-1])
                                      your_data = "Hello"
                                      s.send("your_data")

                                      Can you send us the one complete example code which sends data from fipy to server. Where a local computer in the same network can be used as server.

                                      Thank You

                                      L 1 Reply Last reply Reply Quote 0
                                      • L Offline
                                        livius @Archana Kadam
                                        last edited by livius

                                        @archana-kadam
                                        with default mode AP you must connect your computer to Fipy.
                                        In mode STA you connect your Fipy to computer (most often through router)
                                        After you are connected to the network (local) you can communicate between computer and Fipy.

                                        from network import WLAN
                                        import socket
                                        
                                        wlan = WLAN(mode=WLAN.STA)
                                        # wlan.ifconfig(config=('192.168.0.105', '255.255.255.0', '192.168.0.1', '192.168.0.1')) - you can ommit this line if you need to connect by DHCP
                                        wlan.connect(ssid='mynetwork', auth=(WLAN.WPA2, 'my_network_key'), timeout=30000)
                                        
                                        while not wlan.isconnected():
                                        	machine.idle()	
                                        	
                                        if wlan.isconnected():
                                        	s = socket.socket()
                                        	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                                        	s.connect(socket.getaddrinfo('192.168.0.109', 2345)[0][-1]) #IP of your computer(192.168.0.109) in the same network as your Fipy and port(2345) of socket in listen mode on your computer
                                        	your_data = "Hello"
                                        	s.send("your_data")
                                        

                                        remember that you must have something listen on incoming traffic on your computer then.

                                        think about people first, then computers

                                        A 1 Reply Last reply Reply Quote 0
                                        • A Offline
                                          Archana Kadam @livius
                                          last edited by livius

                                          @livius
                                          We have successfully connected to the server by the given code, but we are getting an error in line number 14, im sending the screenshot please go through the file0_1521551509504_5596a1e4-c670-4266-b053-1b5c3d7b1205-image.png

                                          L 1 Reply Last reply Reply Quote 0
                                          • L Offline
                                            livius @Archana Kadam
                                            last edited by livius

                                            @archana-kadam
                                            remove line 13 s = socket.socket()

                                            P.S> i have blurred your password on the screenshot

                                            think about people first, then computers

                                            A 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
                                            • 2
                                            • 3
                                            • 4
                                            • 2 / 4
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom