How to make communicate on raspberry pi over TCP/IP

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
kamorn
Posts: 4
Joined: Mon Jan 21, 2019 8:22 pm
Contact:

How to make communicate on raspberry pi over TCP/IP

Post 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

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

Post by LeighM »

Hi,
Could you attach your Flowcode project file for us to look at?
Thanks

kamorn
Posts: 4
Joined: Mon Jan 21, 2019 8:22 pm
Contact:

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

Post 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.
Attachments
Flowcode1-rev1.fcfx
(13.85 KiB) Downloaded 204 times
Last edited by kamorn on Fri Mar 15, 2019 10:51 am, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

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

Post 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()

kamorn
Posts: 4
Joined: Mon Jan 21, 2019 8:22 pm
Contact:

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

Post by kamorn »

Hi,
Thank you, I will fixed and try it again.

Regard

Post Reply