Raspberry Pi and PC communication - Page 1
Forum section: electronics / general

author: mmoreau
author_rank: Contributor
timestamp: September 02, 2020, 11:25:23 am
content: I have a Raspberry Pi 0W that is connected to my network through wifi(Static IP). It has an E-Ink display, buttons and creates a log based off of button pushes(Python script working with text file). My current way of correcting the log when I mess up is to go into the file using SFTP and manually editing it. The file is a text file with lines formatted like this(08*31*0*4*1*1*). My plan is to use Tkinter so that I have a GUI that not only edits the file when needed(really it will just send a command that the script that's running on the Pi will execute, I can do that) but allows me to view the data on my computer easily when I cannot see the E-Ink display.So, to sum it up, I want to send basic messages between the PC and Pi, where the Pi will always be listening will do the correct thing. I am not sure how to do that or if it is possible. I want to have a python script always listen to network traffic and then send out what I need. I am really not sure where to start looking. I don't think it needs to stream the data(I would prefer that it wouldn't flood my network needlessly), just send out packets when requested. It is fairly important to me that everything is edited on the Pi, so using FTP to grab the file itself is out of the question.Any suggestions of what to look into would be appreciated.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 02, 2020, 03:20:38 pm
content: As you have a working TCP/IP stack, you can simply open a port in python and listen to it.A simple "chat server" in Python is probably 10 lines of code.You can use a program like telnet, putty or netcat to communicate with it, and in a later stadium implemet that part in your tkinter program.

author: mmoreau
author_rank: Contributor
timestamp: September 02, 2020, 08:46:29 pm
content: Thanks, I will look into TCP/IP. That gives me a possible direction to look in.As an update, right after I posted this, I had another look at flask. By itself it really didn't look like what I wanted but this time I used it to send the basic info on the index page and I was able to parse it and use it the way I wanted. I could execute commands based on what page I request.But this seems so sketchy. I know that when using a browser, delayed connection result in the browser sending multiple requests and that would be a problem(I had this issue on an ESP32 project and that was solved my writing my own app that would only make one request). I'm not sure how python will handle it. If it only sends one request then that is fine.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 10, 2020, 10:14:17 am
content: Flask is ... a web browser / http library I think ( I do not use pytyhon much). This is a few layers over the basic TCP/IP.Just opening a port and sending some data through it is very simple, and a good exercise to get a grip on the basics too before venturing into more complicated libraries.MQTT may be a very interesting library for you. The idea is that you have machine nodes (such as a battery powered temperature sensor) that sleeps mostly and wakes up and does it's thing every now and then. Then there is a server that is always available, collects data from multiple points and makes it available to "others".Node Red is also related to this. It's a sort of graphical programming language as I understand and it's apparently standard installed on raspi's.But anyway, having a good grasp of how TCP/IP works lays the foundation for all these "higher" libraries and gives you a foundation to build upon.