Forum > Networking and Web Programming

[SOLVED] TTCPClient and Stream Write Error (Raspberry Pi 3B+)

(1/2) > >>

washburn_it:
Hi,

almost 2 years ago I developed a small Lazarus program that reads electric consumptions data from an Eastron SDM-120C and transmits those data to a local python program that sends those data via MQTT to Cayenne "MyDevices" web service.
The "thing" has worked correctly for all this time, now the error in the subject started to appear.
The Lazarus program, the python program and Raspbian were not updated or modified during all this time.
The communication between the Lazarus program and the python program is made through TCP where the python program acts as server.
The component that I used is the "TTCPClient", Lazarus is the v2.0 (the one present in the Raspbian Buster repository).
The error "stream write error" appears after some minutes (never after the same amount of time) but I can't find the reason why, apparently it's all ok.
The thing that I'm sure of is that the python program is running and "listening" for a client to connect (I can read it on the screen).
When the error appears I have to close and execute the Lazarus program again, it works for 10/15 minutes and then back again the error.
The sequence is:

- data are read from the SDM120C
- data are sent to the python program via TCP (port 9000)
- connection is closed
- delay of 2 seconds then the cycle repeats

what should I check?
Surely something happened but, at the moment, I have no idea what happened.
Thank you, regards.


Roberto

rvk:
I don't use Lazarus for my SDM120C but I use a small c++ program to read from it (https://github.com/gianfrdp/SDM120C). Then I just use a bash file which reads the SDM120C and directly push it into a influxdb server every few seconds.

But your problems are with writing to the python program... Why don't you directly send data to MQTT from Lazarus in that case? It would think that would be much simpler. https://github.com/bkeevil/mqtt Or does that python program do something additional?

washburn_it:
I used this way because I never found a MQTT implementation for Lazarus under Raspberry so since python had already specific Cayenne libraries, I choose to send data from "Lazarus" to "python" using a simple tcp communication.
I'm also using the c++ program that you mentioned to read from the SDM, I put the readings into a text file that the Lazarus program reads and extracts data.
It's not the python program that does something "more" but the Lazarus program that activates an alarm (piezo) if the current power gets over 3.3 kW (it's the max power allowed in a house) and display current data (and some other calculated "statistics") on a screen.

I had a look at that github link but he used LNet libraries that I used in the past and I had to uninstall due to a lot of issues.

rvk:

--- Quote from: washburn_it on September 29, 2021, 05:00:18 pm ---I'm also using the c++ program that you mentioned to read from the SDM, I put the readings into a text file that the Lazarus program reads and extracts data.
--- End quote ---
Yikes. That's another (two) layer(s)/program(s)  :D

So, from SDM120C program to text-file to Lazarus to Python to MQTT  :D
A lot of places things can go wrong.


--- Quote from: washburn_it on September 29, 2021, 05:00:18 pm ---It's not the python program that does something "more" but the Lazarus program that activates an alarm (piezo) if the current power gets over 3.3 kW (it's the max power allowed in a house) and display current data on a screen.
--- End quote ---
Ah, ok. I would at least eliminate one program. So either directly read the SDM120C output into python (which sends it to MQTT but you would need to know how to program in python) or do the same with Lazarus. I would also read the SDM120C output directly from input and not via a file (https://wiki.freepascal.org/Executing_External_Programs).

BTW. The github link for MQTT in Lazarus was just the first one I could find. There are (a lot) more I'm sure. Searching for MQTT on this forum would help too.
(This is another one with synapse instead of LNET https://github.com/ZiCog/mqtt-free-pascal)

O, and why are you communicating via port 9000 with that python program? Is that a standard program? Can't it take other forms of input?

And what does MQTT do with the data?

washburn_it:

--- Quote ---output directly from input and not via a file (https://wiki.freepascal.org/Executing_External_Programs).
--- End quote ---

well, it may be an idea  :D


--- Quote ---O, and why are you communicating via port 9000 with that python program? Is that a standard program? Can't it take other forms of input?
--- End quote ---

I used that port value because I know that certainly it's not used locally, I could have used another port (e.g 9080) but it's just the port to communicate with the python program that is acting as TCP server.

Could you suggest other ways to communicate with python?


--- Quote ---And what does MQTT do with the data?
--- End quote ---

MQTT is the protocol used by Cayenne to acquire data from a device and display them in a web page with several widgets and gauges (also graphs).

Navigation

[0] Message Index

[#] Next page

Go to full version