Page 1 of 1

How to make communicate on raspberry pi over TCP/IP

Posted: Thu Mar 14, 2019 6:00 pm
by kamorn
Hi, I try to use flowcode8 to communicate over TCP/IP with TCP/IP raspberry pi function but I can't sent or receive data anything. could you give example for TCP/IP communication to me.

actually, I design flowchart in below and use 2 LED for check status when execute code.
https://drive.google.com/open?id=1LNAiT ... bANCjftGaa

Moreover, I just test by python with socket function from some web page. Then, I can make a communicate between my notebook and pi.

Client (my notebook ==>> IP : 192.168.2.99)

Code: Select all

#!/usr/bin/python3
import socket

host = socket.gethostname()
port = 5052                   # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.connect((host, port))
s.connect(("192.168.2.15", port))
s.sendall(b'Hello')
data = s.recv(1024)
s.close()
print('Received', repr(data))


Server (raspberry pi3 B ==>> IP : 192.168.2.15)

Code: Select all

#!/usr/bin/python3
import socket

host = '192.168.2.15'        # Symbolic name meaning all available interfaces
port = 5052     # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))

print (host , port)
s.listen(1)
conn, addr = s.accept()
print('Connected by', addr)
while True:

    try:
        data = conn.recv(1024)

        if not data: break

        print ("Client Says: "+str(data))
        conn.sendall(b'Server Says:hi')

    except socket.error:
        print ("Error Occured.")
        break

conn.close()

from code client above, I try to use send some data to my note via LAN cable and use my notebook lookup something but it can't found.

Moreover, I would like to use function SendTo from TCPIP(Raspberry pi) reference in your manual on website but it didn't have on your product.
please update function on above and give me some example

Regard

Re: How to make communicate on raspberry pi over TCP/IP

Posted: Thu Mar 14, 2019 6:22 pm
by LeighM
Hi,
Could you attach your Flowcode project file for us to look at?
Thanks

Re: How to make communicate on raspberry pi over TCP/IP

Posted: Thu Mar 14, 2019 6:47 pm
by kamorn
LeighM wrote:Hi,
Could you attach your Flowcode project file for us to look at?
Thanks
Sorry, I just see attachments file tab and please help us.

Re: How to make communicate on raspberry pi over TCP/IP

Posted: Fri Mar 15, 2019 9:08 am
by LeighM
Hi,
You just have some of the function calls in the wrong order.

For a server:

Code: Select all

Initialise()
SocketOpen()
Listen()
loop 
  {
  Receive()
  Send()
  }
SocketClose()
For a client:

Code: Select all

Initialise()
SocketOpen()
Connect()
loop
  {
  Send()
  Receive()
  }
SocketClose()

Re: How to make communicate on raspberry pi over TCP/IP

Posted: Fri Mar 15, 2019 9:29 am
by kamorn
Hi,
Thank you, I will fixed and try it again.

Regard