Communication between two mangOH board using IoT Cards

Hi every,

I’m tring to use two mangOH boards to communicate with each other, I also have two IoT Cards(Wifi/Bluetooth).

First of all I have followed the instruction from WiFi Service Plugin to set up the WiFi Service.
http://legato.io/legato-docs/latest/external_proj_mainpage.html

I have successfully used all of the Sample Apps including WiFi Client, WiFi Access Point, WiFi Access Point Web. Basiclly I know now how to establish the Wifi connection between two devices(for me two boards). But all of those apps didn’t mention how to customize the serial port to send the data from one IoT wifi card to the other one.

If I want to send a message like “Hi” to the other board, is that possible to wirte this sentence in the programmfile and use some API to send it or receive it? Are there any API that I can use to support this app?

Or can I use the AT command to communicate in the console arfter connecting those two board?

Need more Information.

Thx at first

Genfory

Hi Genfory,

What do you mean by “how to customize the serial port to send the data …”? In fact, if you want to communicate via WiFi from one board to another one, you need to setup one board in WiFi client mode and the other board in WiFi Access Point mode. Then, when the WiFi connection is established you can use the linux netcat tool (nc) to communicate between the 2 boards via a TCP or an UDP socket.

For example:
On WiFi client side, you can send a file “file.txt” using a TCP socket on port 1337 using the following command:

cat file.txt | nc -l 1337

and on WiFi Access Point side, you can listen the TCP socket on port 1337 and save the received content in file.log file using the following command:

nc -l -p 1337 > file.log

Hope it helps.
Best Regards,

José

Hi

Thanke for ur support.

So far my problem is connection between two mangOH boards. First of all I need to set up the different mode for two board, but I showed alwalys “no address range available for DHCP request via eth0”. The details u can check the other post.
http://mangoh.discourse.group/t/no-address-range-available-for-dhcp-request/325

Ur suggest helps a lot, I will try it later. But If I want to establish a talk between two board, is that also possible? It’s like writing sentences directly in the code files, also including the WiFi set up, communicate content and then make a app. I just need to run the app, the two boards will automaticly talk. I can use those apps to simulate the temperature control or deal with other data from sensor.

Thx in advance

Genfory

Hi
I have tried it again the other day, dont know why it could works. Now I can connect the two boards with WiFi.

I also have used the nc tool like u said to send a file using the TCP socket,the problem is about finding the file.

I just create a file in the desktopin Linux system. Is it the problem about the path or address by creating the file, How can I create the file with the right path or how should I change the address?

And I also have a question about socket API. Is there any socket API in Legato supporting communication between two boards?

If U have the further information,please let me know.
Thx

Genfory

Hi Genfory,

When you have successfully connected your 2 boards with a WiFi connection, could you please perform the following steps/commands:

  1. From mangOH1 board, ping @IP-address-of-mangOH2-board
  2. From mangOH2 board, ping @IP-address-of-mangOH1-board

If ping commands are successful:

  1. On mangOH1 board: perform the following command:

nc –l 1234 > filename.out

  1. On mangOH2 board: perform the following command:

Echo “Hello MangOH” > filename.in
nc @IP-address-of-mangOH1-board 1234 < filename.in

At that level, you should have received (on mangOH1 board) in filename.out file the content of filename.in (from mangOH2 board)

Regarding Legato API for sockets, as far as know it doesn’t exist…
Regards,

José

Hi José,

According to step 1 and 2 I’m tring to ping the two board. I’m not quite sure which ip address should I ping for the client and server side, because the address for two board is default 192.168.2.2,so I test a lot.

The following is the code from client side.

I use mangOH1 board as client side and mangOH2 board as server side. At first establish the connection and mangOH1 get a IP address from mangOH2:

root@swi-mdm9x15:~# /sbin/udhcpc -R -b -i wlan0
udhcpc (v1.22.1) started
Sending discover…
Sending select for 192.168.10.78…
Lease of 192.168.10.78 obtained, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 192.168.10.1

ping mangoh io successfully:
root@swi-mdm9x15:~# ping mangoh.io
PING mangoh.io (185.31.17.133): 56 data bytes
64 bytes from 185.31.17.133: seq=0 ttl=51 time=24.019 ms
64 bytes from 185.31.17.133: seq=1 ttl=51 time=35.403 ms

I use the USB0 port im Laptop to connect the mangOH board,check the configuration:
root@swi-mdm9x15:~# ifconfig usb0
usb0 Link encap:Ethernet HWaddr C6:46:2D:C7:9D:3E
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::c446:2dff:fec7:9d3e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2974 errors:0 dropped:0 overruns:0 frame:0
TX packets:1195 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:330953 (323.1 KiB) TX bytes:222604 (217.3 KiB)

It shows the inet addr ist 192.168.2.2 so I try to ping this address successfully:
root@swi-mdm9x15:~# ping 192.168.2.2
PING 192.168.2.2 (192.168.2.2): 56 data bytes
64 bytes from 192.168.2.2: seq=0 ttl=64 time=0.611 ms
64 bytes from 192.168.2.2: seq=1 ttl=64 time=0.366 ms

From the server side I got the following code.

The select ip address from DHCP by client side is 192.168.10.78,so I try to ping the client side using this address successfully:
PING 192.168.10.78 (192.168.10.78): 56 data bytes
64 bytes from 192.168.10.78: seq=0 ttl=64 time=130.841 ms
64 bytes from 192.168.10.78: seq=1 ttl=64 time=150.862 ms
64 bytes from 192.168.10.78: seq=2 ttl=64 time=174.272 ms

I also use the USB0 port in second Laptop to connect the mangOH board,check the configuration:
root@swi-mdm9x15:~# ifconfig usb0
usb0 Link encap:Ethernet HWaddr FA:01:53:CD:F1:53
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::f801:53ff:fecd:f153/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5277 errors:0 dropped:0 overruns:0 frame:0
TX packets:4043 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:448058 (437.5 KiB) TX bytes:1117101 (1.0 MiB)

It shows the inet addr ist also 192.168.2.2 so I try to ping this address successfully:
root@swi-mdm9x15:~# ping 192.168.2.2
PING 192.168.2.2 (192.168.2.2): 56 data bytes
64 bytes from 192.168.2.2: seq=0 ttl=64 time=0.763 ms
64 bytes from 192.168.2.2: seq=1 ttl=64 time=0.519 ms

I also check the connected network with this device:
root@swi-mdm9x15:~# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1534 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5037 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN
tcp 0 128 192.168.2.2:22 192.168.2.3:49218 ESTABLISHED
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 :::53 :::* LISTEN
udp 0 0 0.0.0.0:1534 0.0.0.0:*
udp 0 0 0.0.0.0:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 :::53 :::*
target=“1”>

It seems that I can ping from both side, then I try the step 3 by client side,but the same problem comes back:
root@swi-mdm9x15:~# nc -l 1234 > filename.out
nc: bad address ‘-l’

Can u tell me which ip address should I ping and if my steps are right?

Regards,
Genfory

Hi Genfory,

You have to use the IP addresses on WiFi network interfaces (and not on USB interface). Thus, please use command “ifconfig -a” to list the configuration of all network interfaces.
Then use the IP addresses related to wlan0 network interfaces for the ping test.

Regards,

José

Hi José

Thx for ur quick response.

I use the command “ifconfig -a” and get the wlan0 network interfaces from both sides.
The mangOH1 board inet addr:192.168.10.78
The mangOH2 board inet addr:192.168.10.1
And then I successfully ping from one side to the other side, I have tried in the each terminal, it means the connection is established.

The next is step 3, I try the command in the client side(mangOH1 board):
root@swi-mdm9x15:~# nc -l 1234 > filename.out
nc: bad address ‘-l’

The same problem. I try to install the nc tool again:
legato@legato-VM:~$ sudo apt-get install netcat

And the step 3 and 4 or the others, In the mangOH root they don’t work, the echo could not be found:
root@swi-mdm9x15:~# nc -l 1234 > filname.out
nc: bad address '-l’
root@swi-mdm9x15:~# nc -help
BusyBox v1.22.1 (2016-08-11 20:28:21 PDT) multi-call binary.

Usage: nc [IPADDR PORT]

root@swi-mdm9x15:~# nc -lp 1234
nc: bad address '-lp’
root@swi-mdm9x15:~# nc -l -p 1234
BusyBox v1.22.1 (2016-08-11 20:28:21 PDT) multi-call binary.

Usage: nc [IPADDR PORT]

In the client side localhost I try the following command:
legato@legato-VM:~$ nc -l 1234 > filename.out
legato@legato-VM:~$ nc -lp 1234
1
2
legato@legato-VM:~$ nc -l -p 1234
we can chat

And from the server side localhost:
legato@legato-VM:~$ nc 192.168.10.11 1234
nc localhost 1234

No matter what I send from one board, the other one just can not receive that, there are no responses.

I’m confused where should I perform the command, in the localhost or in the SSH root@192.168.2.2??
When I transport a file should I create it at dektop or somewhere or just perform the command, it would build a new one with the filename?

Regards,

Gnefory

Hi Genfory,

Perfect for the ping test :slight_smile:
Regarding the remaining part, sorry but as I haven’t currently 2 mangOH boards available, I gave you the procedure executed on an Ubuntu Linux computer and I forgot that netcat tool on WP module embedded on mangOH board is the BusyBox release (with limitations). Besides, Busybox could be compiled without nc listening capabilities. Then you might not use the mangoh board in this listening mode without a kernel recompilation.
If your goal is to communicate between 2 mangoh boards, you can also implement a socket communication in your Legato application.

Regards,
José

Hi José,

Thx for ur answer, it helps already a lot~

I’m tring to programm a new App to establish the soket communication.
My plan is on the basis of WiFi Client and WiFi Server provided by Legato adding a TCP socket(using other libraries and headers).
I have found a API by Legato:
http://legato.io/legato-docs/latest/c_fdMonitor.html
It seems this API supports monitoring an fd. U said there are no API supporting this kind of communication. But can I use this API, or just other fremd libraries are better?

Besides I have also a question about Socket. I saw a lot of examples metioned that by the Client side I need to set a socket port to establish the communication. I didn’t find any docu describe which port is for TCP socket port, should I use port 1337 or there are any other port? And can you provide me some link so that I can know, which kind of port I’m going to use?

Regards

Genfory