If I correctly understood what you want is basic python tx.py
and rx.py
which communicate in both real and simulation environment. Then answer is yes.
For Simulation:
You can run the 2-node-network.groovy
from samples
folder.
//2-node-network.groovy
import org.arl.fjage.*
///////////////////////////////////////////////////////////////////////////////
// display documentation
println '''
2-node network
--------------
Node A: tcp://localhost:1101, http://localhost:8081/
Node B: tcp://localhost:1102, http://localhost:8082/
'''
///////////////////////////////////////////////////////////////////////////////
// simulator configuration
platform = RealTimePlatform // use real-time mode
// run the simulation forever
simulate {
node 'A', location: [ 0.km, 0.km, -15.m], web: 8081, api: 1101, stack: "$home/etc/setup"
node 'B', location: [ 1.km, 0.km, -15.m], web: 8082, api: 1102, stack: "$home/etc/setup"
}
Now open 2 seperate ipython3
terminal to test the functionality.
I would recommend open the rx
side first so you don't miss the transmission.
C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from unetpy import UnetSocket
...: from unetpy import *
...:
...: s = UnetSocket('localhost', 1102)
...: modem = s.getGateway()
In [2]: rx = modem.receive(RxFrameNtf, 5000) # this will wait till you receive ntf
...: # print rx data, you will get this once you tx data from other side
...: print('from node', rx.from_, ':', bytearray(rx.data).decode())
Out[2] from node 204 : hello!
On Tx
side :
C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from unetpy import UnetSocket
...:
...: s = UnetSocket('localhost', 1101)
In [2]: s.send('hello!', 0)
Out[2]: True
In [3]: s.close()
You can also run this as tx.py
and rx.py
. Borrowed from Unet Documentations - section 2.5 .
# tx.py
from unetpy import UnetSocket
s = UnetSocket('localhost', 1101)
s.send('hello!', 0)
s.close()
# rx.py
from unetpy import UnetSocket
from unetpy import *
s = UnetSocket('localhost', 1102)
modem = s.getGateway()
rx = modem.receive(RxFrameNtf, 5000)
print('from node', rx.from_, ':', bytearray(rx.data).decode())
s.close()
For real modems, you just need to change the IP address
accordingly in the script and it would work flawlessly on modems as well.