Home › Forums › V-Control General › [Solved] Sending commands via TCP did not work
- This topic has 4 replies, 2 voices, and was last updated 7 years, 3 months ago by
Dierk.
-
AuthorPosts
-
November 9, 2015 at 11:49 #639
Marcus_Klein
Participanttried to start a task via TCP remote service, listening on 10101, which did not work for me.
Used were the following lines under raspbian:
echo “405scrRunTask5Shutdown_All_PCs6” > /dev/tcp/192.168.100.1/10101
echo “(4)0(5)scrRunTask(5)Shutdown_All_PCs(6)” > /dev/tcp/192.168.100.1/10101
echo “(4)2(5)H(5)(6)” > /dev/tcp/192.168.100.1/10101And the result was always a lost connection.
-
This topic was modified 7 years, 3 months ago by
Dierk Walter.
-
This topic was modified 6 years, 8 months ago by
Dierk Walter.
November 9, 2015 at 11:50 #640Dierk
ParticipantHi Marcus, thank you for joining us.
The message “lost connection” is impossible if you are using V-Control remote services. If V-Control act as remote server it could not loose a connection because the client decides to connect or not. Only the client can lose a connection. A server only offers a connection. If a client disconnects, then the connection is ended, but from the servers point of view the connection is not lost, the client simply ended it.
I suspect that you have set up a device, probably a generic device, that should connect to your Raspberry Pi. In that case you need a TCP sever on your raspberry, which is impossible to establish by echo commands (as far as I know and surely not as you did in your example).If you use the Raspberry Pi as TCP client (and your demo code suggests that this is what you want to do), you need to set up V-Control as remote server. Select “Configure -> Options” from V-Controls main menu and select the tab “TCP”. Choose a port and check the box “Enable TCP Services”.
Now V-Control is ready to receive commands by its remote control protocol. The protocol is not pure ASCII code. I’m not so familiar with Linux bash, but I know that sending a command such asecho “(4)0(5)scrRunTask(5)Shutdown_All_PCs(6)” > /dev/tcp/192.168.100.1/10101
could not work. The reason is that the command and parameter separators in the V-Control remote protocol are not ASCII characters. As explained here http://v-control.com/wiki/doku.php/remoteprotocolgeneral you have to send the digital value as separator.
If you type
echo “(4)0(5)scrRunTask(5)Shutdown_All_PCs(6) > /dev/tcp/192.168.100.1/10101in your Linux terminal, you send the braces and the “4” as ASCII code. “4” is ASCII code 52. You need to send 4 as value, and no braces. It is explained in the documentation (possibly not clear enough). You have to send values in braces as digital value. I don’t know how to to this in a bash, an example in BASIC language looks like this:
Dim s as string
s = chr(4) + “0” + chr(5) + “scrRunTask” + chr(5) + “Shutdown_All_PCs” + chr(6)There is also a Tutorial explaining the difference using remote services and device events here: http://v-control.com/wiki/doku.php/tutorials:multiple_v-io_boxes_for_push_button_events
November 9, 2015 at 11:51 #641Marcus_Klein
ParticipantHello Dierk,
thank you for your suggestions.
And indeed, I used the remote server of V-Control.
I will try to modify the string and post the result here.Regards,
Marcus
November 9, 2015 at 11:51 #642Marcus_Klein
ParticipantHello again,
I wrote a Python script to send the string via TCP socket:
#!/usr/bin/python
import socket
import sys# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (‘192.168.0.1’, 10101)
sock.connect(server_address)s = chr(4) + “0” + chr(5) + “scrRunTask” + chr(5) + “Shutdown_All_PCs” + chr(6)
try:
# Send data
print >>sys.stderr, ‘sending “%s”‘ % s
sock.sendall(s)finally:
print >>sys.stderr, ‘closing socket’
sock.close()This works for me 😉
Thanks again for your support and your patience, Dierk!
November 9, 2015 at 11:51 #643Dierk
ParticipantHi Marcus,
thank you for sharing your code.
Dierk
-
This topic was modified 7 years, 3 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.