Sending packets via WiFi from Gateway to PC
-
Hello everyone,
I'm quite new with LoPy and had very limited knowledge in network. I followed a simple tutorial on setting up a server on PC and a client on Pycom but it didn't connect with PC.
PC (server):
import socket # Import socket module s = socket.socket() # Create a socket object host = name # Get local machine name port = port_number # Reserve a port for your service. s.bind((host, port)) # Bind to the port s.listen(5) # Now wait for client connection. while True: c, addr = s.accept() # Establish connection with client. print 'Got connection from', addr c.send('Thank you for connecting') c.close() # Close the connectionPycom(client):
import socket # Import socket module s = socket.socket() # Create a socket object host = name # Get local machine name port = port_number # Reserve a port for your service. s.connect((host, port)) print(s.recv(1024)) s.close # Close the socket when doneI'd like to send simple packets of data from Pycom using socket.send() and receive it in my laptop using socket.recv(). However, the problem I'm encountering is that as I run the code in Pycom, I'm getting OSError: -1 in s.connect(). Help is very appreciated :)
-
@finnzc
did you connected Lopy by Wifi to your router?
https://docs.pycom.io/chapter/tutorials/all/wlan.html -
No, I haven't connected LoPy to the router. I was thinking of sending WiFi packets directly to the laptop. Could you explain why is connecting to the router necessary?
Thanks @livius -
@finnzc if you want to send the wifi paquet to your laptop you still need to connect the LoPy to your laptop with maybe your laptop setup as AP.
-
hi @finnzc
I suggest a quick google of how Wi-Fi networks work may be useful
To answer you question - in order for devices to communicate in WiFi they all need to be joined to the same network. This can be done one of two ways
A) Using a router - this is the most common way for example your LoPy, Laptop etc are all connected to your "home wifi" which is a router advertising something called an SSID. The router keeps tracks of all devices on the network and is able to pass packets between them
B) Using your laptop as a router. You can configure your latpop to not join a network instead act as the router itself. I don't recommend this path as it does require a good understanding of wifi networking principles
Andrei
-
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