jbiss92
Posts: 5
Joined: Tue Apr 14, 2015 11:44 pm

RS232 Wifi Server

Tue Apr 14, 2015 11:51 pm

Hi I am a long time lurker and this is my first post.

I have a mobile device connected to a wifi access point hosted on my raspberry pi. My raspberry pi development is generating rs232 messages. On the mobile device is a 3rd party application connecting to the pi via wifi and listening for rs232 messages on the set IP address and port.

My question is - how do I replicate an exact rs232 data flow? I have already dabbled in pushing out messages in rs232 format using simple sockets with no luck. (I can see them being received on the mobile device using a telnet client: but the application doesn't like them).

I understand I may need to use a serial connection so I can set baud rate as opposed to just pushing the messages over a socket ? Any help or advice is greatly appreciated.

klricks
Posts: 6543
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: RS232 Wifi Server

Wed Apr 15, 2015 1:21 pm

I don't quite understand your setup.
I use a program on the RPi; ser2net to send RS232 data over network. I then can see serial stream and interact with serial device on client computer using Realterm terminal software. http://realterm.sourceforge.net/

[Serial Device]------> [RS232 to TTL adapter]-------> [RPi]--------> Network (WIFI or wired) - - - - - - - - > [Client computer]
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

jbiss92
Posts: 5
Joined: Tue Apr 14, 2015 11:44 pm

Re: RS232 Wifi Server

Wed Apr 15, 2015 1:30 pm

Thank you very much for your reply. I wasn't quite clear about my setup. I have :

[RPi]--------> Wifi Network --------> [Client computer with 3rd party app]

The RPi itself is generating the data using various sensors. It is this data which I wish to transmit over the network. (I have put the data into NMEA format). The Client application (which I cannot change) is expecting to receive a rs232 data flow. Pushing the NMEA messages across the network using a simple socket structure is not working. They are definitely being received on the correct port as I can see them being received using Telnet on the Client computer.

Would ser2net 'wrap' these messages so that they appear to have been transmitted as a legit RS232 data flow?

klricks
Posts: 6543
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: RS232 Wifi Server

Wed Apr 15, 2015 1:42 pm

jbiss92 wrote:Thank you very much for your reply. I wasn't quite clear about my setup. I have :

[RPi]--------> Wifi Network --------> [Client computer with 3rd party app]

The RPi itself is generating the data using various sensors. It is this data which I wish to transmit over the network. (I have put the data into NMEA format). The Client application (which I cannot change) is expecting to receive a rs232 data flow. Pushing the NMEA messages across the network using a simple socket structure is not working. They are definitely being received on the correct port as I can see them being received using Telnet on the Client computer.

Would ser2net 'wrap' these messages so that they appear to have been transmitted as a legit RS232 data flow?
The data appears on client terminal program as if the device was directly connected. (Bi-directional control)
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

JF002
Posts: 94
Joined: Sat Feb 04, 2012 8:49 am
Contact: Website

Re: RS232 Wifi Server

Wed Apr 15, 2015 9:03 pm

On the mobile device is a 3rd party application connecting to the pi via wifi and listening for rs232 messages on the set IP address and port
That doesn't make sense...

RS232 is a standard for serial communications. It defines how to send and receive bits on minimum 3 wires (ground, tx and rx).
IP (which is used on Wifi) is a familly of network protocol, it is part of the OSI model.

This is just theory, but what I mean is that you cannot just send the bits or the bytes on an IP network the same way than on an RS232 communication. The electrical levels, timings, coding, protocols,... are not the same.

If you need to send data to a mobile device via Wifi, then a simple socket should work. You don't have to worry about eletrical levels or baudrate but... you need to know how to format the data correctly so that the mobile application will be able to process them.
You'll need some kind of documentation of the protocol(s) that is(are) used by the application. I don't know NMEA, but it seems to be a transmission protocol, it seems to be a good start. But the application may need some data before or after the message, for example. Or it may need a specific encoding (binary, ascii,...), little or big endian,...
My web site : https://codingfield.com

jbiss92
Posts: 5
Joined: Tue Apr 14, 2015 11:44 pm

Re: RS232 Wifi Server

Thu Apr 16, 2015 1:15 pm

But the application may need some data before or after the message, for example. Or it may need a specific encoding (binry, ascii,...), little or big endian,...
Thankyou both for your input - JF002 you're absolutely right and I have done some further research. According to the specification the messages need to be formatted as described here:
The data sent is all in printable ASCII form (data bit 7 is always zero in NMEA 0183 data transmissions, and all characters should be between ASCII HEX 20 and HEX 7E)
I know this is moving away from Raspberry Pi discussion - but do you know what 'printable ASCII form' is referring to? I have seen various sources online where the "$" character is depicted by (0x24), or 036, or other variations?

Cheers again for the very helpful posts.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: RS232 Wifi Server

Thu Apr 16, 2015 1:49 pm

jbiss92 wrote:
But the application may need some data before or after the message, for example. Or it may need a specific encoding (binry, ascii,...), little or big endian,...
Thankyou both for your input - JF002 you're absolutely right and I have done some further research. According to the specification the messages need to be formatted as described here:
The data sent is all in printable ASCII form (data bit 7 is always zero in NMEA 0183 data transmissions, and all characters should be between ASCII HEX 20 and HEX 7E)
I know this is moving away from Raspberry Pi discussion - but do you know what 'printable ASCII form' is referring to? I have seen various sources online where the "$" character is depicted by (0x24), or 036, or other variations?

Cheers again for the very helpful posts.
"Printable ASCII form" means data bit 7 is always zero, and all characters should be between ASCII HEX 20 and HEX 7E.

I agree that your problem description makes no sense. Your "3rd party application" is not expecting RS232 data. It is expecting a stream of bytes coming in to a socket.

You are generating messages on the Pi, and sending them to a host address and port, but the "3rd party application" doesn't like them. Are you sure you are generating them correctly? NMEA data strings usually have a checksum. Are you calculating it correctly?

Do you have a sample NMEA string that you know should be accepted? If so, use your program to send it. If it works then you have eliminated a bunch of potential problems.

klricks
Posts: 6543
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: RS232 Wifi Server

Thu Apr 16, 2015 1:53 pm

jbiss92 wrote:
But the application may need some data before or after the message, for example. Or it may need a specific encoding (binry, ascii,...), little or big endian,...
Thankyou both for your input - JF002 you're absolutely right and I have done some further research. According to the specification the messages need to be formatted as described here:
The data sent is all in printable ASCII form (data bit 7 is always zero in NMEA 0183 data transmissions, and all characters should be between ASCII HEX 20 and HEX 7E)
I know this is moving away from Raspberry Pi discussion - but do you know what 'printable ASCII form' is referring to? I have seen various sources online where the "$" character is depicted by (0x24), or 036, or other variations?

Cheers again for the very helpful posts.
Reed about printable ASCII here: http://en.wikipedia.org/wiki/ASCII
24 HEX = 36 DEC. They are the same number.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

jbiss92
Posts: 5
Joined: Tue Apr 14, 2015 11:44 pm

Re: RS232 Wifi Server

Thu Apr 16, 2015 4:09 pm

Thanks again for all the advice everyone.
"Printable ASCII form" means data bit 7 is always zero, and all characters should be between ASCII HEX 20 and HEX 7E.
Please could you expand on this? Here are two sample messages which should be accepted:

Code: Select all

$GPGGA,123627.00,4956.19585,N,01023.67446,E,1,08,3.35,1096.9,M,48.0,M,,*60
$GPGSA,A,3,31,27,14,09,04,12,25,29,,,,,6.55,3.35,5.63*01
What does it mean to ensure that data bit 7 is zero?
Do you have a sample NMEA string that you know should be accepted? If so, use your program to send it. If it works then you have eliminated a bunch of potential problems.
Unfortunately sending these messages over the socket does not work. I am certain they are being received as can see them being received using telnet on the correct port and ip on the device.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: RS232 Wifi Server

Fri Apr 17, 2015 12:08 am

jbiss92 wrote:Thanks again for all the advice everyone.
"Printable ASCII form" means data bit 7 is always zero, and all characters should be between ASCII HEX 20 and HEX 7E.
Please could you expand on this? Here are two sample messages which should be accepted:

Code: Select all

$GPGGA,123627.00,4956.19585,N,01023.67446,E,1,08,3.35,1096.9,M,48.0,M,,*60
$GPGSA,A,3,31,27,14,09,04,12,25,29,,,,,6.55,3.35,5.63*01
What does it mean to ensure that data bit 7 is zero?
It basically means to use characters that are less than 0x7F.
Do you have a sample NMEA string that you know should be accepted? If so, use your program to send it. If it works then you have eliminated a bunch of potential problems.
Unfortunately sending these messages over the socket does not work. I am certain they are being received as can see them being received using telnet on the correct port and ip on the device.
I don't know how you can be using telnet to see this.

Anyway, you are basically fabricating fake GPS data to send to the "3rd party application", right?

jbiss92
Posts: 5
Joined: Tue Apr 14, 2015 11:44 pm

Re: RS232 Wifi Server

Fri Apr 17, 2015 11:43 am

It basically means to use characters that are less than 0x7F.
Okay thank you that makes sense!
I don't know how you can be using telnet to see this.
I can use telnet because my Rpi is hosting the service on a static IP address and Port (192.168.1.1 2000). So when the tablet is connected to the Rpi via the Wi-Fi hotspot I can listen to this address and port to see the data being sent. This is the same address and port which the app is expecting to receive data on. Except it doesn't recognise the data being sent - which is why the question was about the formatting of this data.
Anyway, you are basically fabricating fake GPS data to send to the "3rd party application", right?
Yes.
Thanks again for your help :-)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: RS232 Wifi Server

Sat Apr 18, 2015 5:53 am

Ok, I checked your checksums on the two sample strings you showed, and they are correct.

My two suggestions are firstly, check your line endings. Maybe the remote device is rejecting the data because it's terminated by CR or CR/LF or not. It shouldn't matter, but maybe it does.

Secondly, do you have a real GPS? You could hook that up to the Pi and use ser2net to redirect the real strings to the remote application's port. That ought to work. If it does or doesn't it should tell you something.

Return to “Advanced users”