Girgitt / PJON-python

Pythonic interface to PJON communication protocol.
Other
26 stars 4 forks source link

Add support for EthernetTCP strategy #8

Open drtrigon opened 6 years ago

drtrigon commented 6 years ago

I am planning to use the https://github.com/gioblu/PJON/blob/master/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/Surrogate/Surrogate.ino on an Arduino Yun (or ESP8266). On the "server side" I would like to be able to use PJON-python to access the Surrogate by EthernetTCP.

Can you elaborate on how to implement this and may be provide an example. I would be willing to fork and implement it myself if you wish. Greetings!

Girgitt commented 6 years ago

Hi @drtrigon ! At this time PJON-python uses internally a wrapper on PJON-piper which in turn is a command-line client built from PJON sources. PJON-python uses unnamed pipes to send and receive packets to/from PJON-piper maintained as a sub-process.

A clean way to provide EthernetTCP strategy support would be to extend PJON-piper to use EthernetTCP strategy instead of (additionally to) serial strategy (if EthernetTCP is available in PJON for your platform) and slightly modify PJON-python to initialize PJON-piper in EthernetTCP mode instead of serial.

A kind-of-hacky way is to use an intermediate PJON proxy node - e.g. based on ESP8266. Such a proxy node can be connected via serial to PC or raspi and run proxy code to send packets over EthernetTCP strategy to other nodes. Such setup should work with 50 packtes/sec or more. Not nice but easy.

Yet another way would be to modify PJON-piper to expose interface to assemble (for transmitting) and parse (when receiving) PJON packets only and all TCP transport would occur in pyhon at PJON-python level. This approach is prone to compatibility issues with the PJON code base as it would depend heavily on PJON internal methods.

Yet another way is to implement PJON completely in python - this is how initially PJON-python was written (and still has unused pjon v4 pure-python implementation inside) but this approach was dropped in favor of using PJHON-piper compiled from PJON sources - mainly to reduce maintenance effort which still is quite high given PJON's development pace. So I do not encourage to take this path and suggest taking a look at PJON-piper and extending it to use EthernetTCP strategy additionally to serial.

gioblu commented 6 years ago

Ciao @Girgitt have you seen PJON-cython ? https://github.com/xlfe/PJON-cython

Girgitt commented 6 years ago

Hi @gioblu Actually I have not seen PJON-cython before. Using cython is indeed a neat idea for using PJON source code from python.

An already implemented UDP strategy in PJON-cython could be a solution to @drtrigon problem if using UDP instead of TCP is not an issue and intended platform is Linux.

For strategies more reliable than serial (TCP, UDP) a good solution would be to use cython to interface with PJON only for packets assembly and parsing and rely on python native modules for networking. Such approach should provide a multi-platform compatibility not available currently in PJON-cython (If I am not mistaken after just skimming through the source code).

But as they say "you need to piss with the cock you have" and since my cython experience is zero I will rely on compiling PJON-piper to abstract PJON implementation from python interface to introduce PJON-python compatibility with PJON v8+ versions.

drtrigon commented 5 years ago

Just to say I am currently working with PJON-cython as I am used to the PJON source code anyways (meanwhile). But a working PJON-python written partly or completely in python would be nice too.