Tcp needed when i2c and ssh are used? - c

I'm doing a project where I have 2 raspberry pi zeros connected and a psoc 5 connected to one of the rpi's.
The connection between them are all i2c.
One of the rpi's are considered the "master" and from my android phone I will use ssh to remote control the master.
[Phone] = SSH = [RPi Master] = I2C = [RPi Slave]
||
[PSOC 5]
My teacher told me to consider tcp/ip, but I will still have the 2 rpi's and the psoc connected by wires.
My question therefore is - are there any benefits in doing tcp in my project?

There is no clear way to answer whether TCP is better than I2C without more info about your project, as that is an application-specific question. This question would be easier to answer with a little more detail on your project, including requirements, data rates, etc., but I will try to give you some info based on personal experience.
The only reason to consider TCP/IP between the devices is if the data rate needed is higher than I2C can support, or if it would be useful to keep them separated beyond I2C range.
Creating a program that utilizes TCP to run on your phone and the master would make the system a little more complete, as you would have a program running on the master constantly to automatically accept information from the user and run the commands, rather than having to control it from the command line. This would also force you to create some sort of user-facing program for the phone. From a design perspective for a class project, this could be preferable.
Without knowing why your teacher suggested that it is hard to give you a straight answer; it is possible the suggestion was given not for any real performance reasons but for you to learn about networking, TCP/IP protocols, or to be able to say you have "IoT experience".

Related

Is there a way of "extracting" communication protocol from an old software?

I have an obsolete hardware level/pressure transmitter that communicate with mcu using custom protocol (it appear to be similar to modbus RTU), that hardware comes along with an old commissioning software that works perfectly fine under latest windows, that software contain all communication protocol components that I try to extract and use in something like Arduino to pull data out of transmitter, anyone can help out?
Update - Didn't mentioned above that form of communication here is half-duplex serial communication where master hardware/software query slave transmitter.
Now mentioned to program Arduino mcu to pool data out of transmitter.
What best way of getting readable data out of it?
Again many thanks for all your comments and help!
What you need is called a sniffer. Use that as a keyword and you should be able to find plenty of info here at SO and around the web.
To set the record straight it is actually possible to use Wireshark to sniff on Modbus RTU over serial, see my answer here. If your protocol is similar to Modbus I would start with SerialPCAP.
If you prefer more Windows-friendly solutions you can check these out: 1, 2.
Since Modbus is pretty simple I would say reverse engineering a similar protocol should be, maybe not a piece of cake but just manageable, even if you are not very experienced.
These days when almost everyone is a maker or at least a wannabe, you might want to first take a good look around, maybe somebody else already reverse-engineered that protocol and published it somewhere.
The best tool to analyze a protocol is Wireshark. Run it on the communication link between the Windows machine and the radar. First possibility: the protocol is actually something that Wireshark knows (some trials and errors with the "Decode as" menu may be necessary.) Second possibility, less funny: the protocol is indeed completely proprietary and unknown to Wireshark. At least, Wireshark will make it easier to examine the binary data.

CREG, CGREG, CEREG AT commands

I have to control a modem Cinterion ELS61 with a host application. Can anyone tell me in simple words which is the real difference among at+creg?, at+cgreg? and at+cereg? commands?
I know that cgreg is related to 2G and 3G radio access technology and cereg with 4G/LTE one, but the actual differences are not so clear and neither the relation with the creg command results.
It follows an example from a real case:
AT+CREG?
+CREG: 2,5,"38AD","02531900",7
OK
AT+CGREG?
+CGREG: 2,4
OK
AT+CEREG?
+CEREG: 2,5,"2AF2","02531900",7
OK
What is the difference among the answers to +creg and +cereg? Aren't they quite the same? And by the way, what does it mean that the same cell (02531900) has 2 difference location area codes (i.e. 38AD and 2AF2)?
Thanks for the attention
All the +C*REG commands, as you probably know, query the status of the registration to some network.
The first step is the following categorization:
+CREG, that queries the registration to the circuit switched network.
It is basically the GSM "classic" network, on which voice/data calls and SMSs are based
+C*REG commands, that query the registration to the packet networks.
They are the networks on which the packed data traffic is based. The network allowing the access to internet, to be clear.
+C*REG commands are technology specific commands:
+CGREG queries the registration to GPRS network
+CEREG queries the registration to LTE data packet network, and in some cases is mandatory also to perform tasks that were usually based on GSM: voice calls (if VoLTE, Voice Over LTE, is supported) or to sent SMSs (IMS protocol).
LTE technology, basically, moves almost everithing on packet traffic
The reason why different commands are available (even in the same cellular module) is that different registration processes are required for each sub-network.

SGMII without phy - external loopback on Xlinix Zynq UltraScale+ RFSoC board

I have a costume board with Xilinx Zynq UltraScale+ RFSoC.
I'm using 3 PS_GTR transceivers as sgmii.
2 of them are connected to external Marvell phy and the third connects directly (fixed link - without phy).
In the manufacturing stage i would like to make sure that the direct sgmii interface is assembled correctly - so I made an external loopback between tx and rx sgmii signals.
Now, Is it possible to transmit something through this external loopback and compare with the received data?
Is it possible to ping with yourself? (simple ping command not working: "ping -I eth2 ")
perhaps there is a 'patch' under the 'macb' kernel driver that someone can guide me through?
Thank you all,
Tzipi Kluska
Yes it is possible to ping yourself. Note that linux does or at least used to bypass the hardware when talking to itself and would do the loopback in the IP stack. I recently saw someone within a terminal (window, command line) isolate one network interface, then another another network interface and then it was trivial to use stock tools like ping and iperf to test the link.
Before doing that though, the serdes on your part should have PRBS capabilities (for a reason), some may have internal scope like features that allow you to extract an eye or at least numbers that indicate the quality of the eye. The marvell phy should also have this capability and you can both use a loopback to talk to yourself use various prbs lengths to check the quality of the link (less than one error in so many 10 to the 14th bits or whatever your desired quality is), and then when connected to the marvell repeat that.
Before doing all of this the software is often the hard part and you need to insure you have it working first, so you may wish to do loopbacks inside the fpga that do not have analog issues and get the software worked out, then in the serdes on the edge of the fpga they may have loopbacks in both directions, the marvell as well may have loopbacks in both directions so you can for example go direct fpga to marvell one is the tx and one the rx and vice versa, or you might enable a lan side shallow loopback on the marvell and talk to yourself.
Also depending on these speeds, hand made loopbacks might be noisy so sometimes a pcb based loopback (which also has to be designed) may wish to be deployed.
Can you ping yourself, absolutely. You can use other low level network interfaces like sockets, to make raw packets and talk to yourself through these interfaces as well. Ping, doing a ping flood, iperf, netperf, etc are all fine ways to exercise or get a warm fuzzy about the interface during both development and manufacture test.
Being an fpga you can of course have a test design that you load into the fpga that pushes the external interfaces and reports the bit error rate.

Hosting multiple clients with freemodbus

I am working on a project involving a microcontroller communicating to a PC via Modbus over TCP. My platform is an STM32F4 chip, programming in C with no RTOS. I looked around and found LwIP and Freemodbus and have had pretty good success getting them both to work. Unfortunately, I'm now running into some issues which I'm not sure how to handle.
I've noticed that if I establish connection, then lose connection (by unplugging the Ethernet cable) I will not be able to reconnect (once I've plugged back in, of course). Freemodbus only allows one client and still has the first client registered. Any new clients trying to connect are ignored. It won't drop the first client until after a specific timeout period which, as far as I can tell, is a TCP/IP standard.
My thoughts are...
I need a Modbus module that will handle multiple clients. The new client request after communication loss will be accepted and the first client will eventually be dropped due to the timeout.
How do I modify Freemodbus to handle this? Are there examples out there? I've looked into doing it myself and it appears to be a decently sized project.
Are there any good Modbus packages out there that handle multiple clients, are not too expensive, and easy to use? I've seen several threads about various options, but I'm not sure any of them meet exactly what I need. I've had a hard time finding any on my own. Most don't support TCP and the ones that do only support one client. Is it generally a bad idea to support multiple clients?
Is something wrong with how I connect to the microcontroller from my PC?
Why is the PC changing ports every time it tries to reconnect? If it kept the same port it used before, this wouldn't be a problem
Should I drop the client from Freemodbus as soon as I stop communicating?
This seems to go against standards but might work.
I'm leaning towards 1. Especially since I'm going to need to support multiple connections eventually anyways. Any help would be appreciated.
Thanks.
If you have a limit on the number of modbus clients then dropping old connections when a new one arrives is actually suggested in the modbus implementation guide (https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf)
Nevertheless a mechanism must be implemented in case of exceeding the number of
authorized connection. In such a case we recommend to close the oldest unused
connection.
It has its own problems but everything is a compromise.
Regarding supporting multiple clients...if you think about modbus/rs server - it could only ever have one master at a time. Then replace the serial cable with TCP and you see why it's not uncommon to only support one client (and of course it's easier to program). It is annoying though.
Depending on what you are doing you wont need the whole modbus protocol and implementing the parts you do need is pretty easy. Of course if you have to support absolutely everything its a different prospect. I haven't used freemodbus, or any other library appropriate to your setup, so I can't help with suggestions there.
Regarding the PC using different TCP source port each time - that is how TCP is supposed to work and no fault on your side. If it did reuse the same source port then it wouldn't help you because e.g. sequence numbers would be wrong.
Regarding dropping clients. You are allowed to drop clients though its better not to. Some clients will send a modbus command, notice the connection has failed, reconnect, but not reissue the command. That may be their problem but still nicer to not see it that often where possible. Of course things like battery life might make the calculation different.

emulating a network interface

Can someone possibly explain (within the size of a stackoverflow answer) the code required in order to emulate a network interface? I just know that there is virtualization software out there like Qemu that does this specific type of hardware emulation, but have no idea how this would work. Lots of books will show you how to create a program that listens on a TCP socket, but not create a host that gets its own IP address.
VirtualBox is open source. As a VM, with networking support, it should be sufficient to demonstrate to you what to do, along with a working implementation. https://www.virtualbox.org/wiki/Downloads
It's really depends what do you mean and what do you want to achieve. If you want emulate some real hardware you need via hypervisor's primitive emulate the most aspects mentioned in datasheet of corresponding adapter, if you want introduce some service, e.g. DNS or HTTP service visible in internal network: you need port teach some user land stack (e.g. LWIP or Slirp, or part if you need UDP only or lower) to communicate with hypervisor's internal network.

Resources