The story so far. I Set up a Server and Client using the very helpful Johannes YouTube tutorial, initially I did this on the Raspberry Pi without any issues using "localhost".
https://github.com/Johannes4Linux/Simple-ModbusTCP-Server/blob/master/Simple_ModbusServer.py
I then attempted to set the Client up on my Windows PC using the Ethernet port and connect to the Server (Pi).
I used the "inet" ip address from the "ifconfig" command within the Pi not the address from the "ipconfig" within windows (they were different).
client = ModbusClient(host="192.168.0.16", port=502, debug=True)
client.open()
connect error
False
I have attempted to ping this address "cmd" from windows but the connection times out.
ping 168.168.0.16
Pinging 168.168.0.16 with 32 bytes of data:
Request timed out.
It feels like I am missing something really obvious. If anyone is able to help me I would really appreciate it.
Ok so it turns out I am a bit of a wally. And many crucial concepts were missing from my implementation.
Debugging the problem using ipconfig/all revealed that the ipV4 = 192.168.4.180(duplicate)
I had set the IP adress on the PC and the Pi, I had forgotten that I had changed the dchpcd.conf file. So the devices were trying to obtain the same address within the network subnet.
The below implementation worked for me:
Setup on Pi
from pyModbusTCP.server import ModbusServer, DataBank
server = ModbusServer(host="192.168.4.181", port=502, no_block=True)
Setup on PC
from pyModbusTCP.client import ModbusClient
client = ModbusClient(host="192.168.4.181", port=502)
client.open()
I found this guide very useful in my networking refresher spell: https://www.ionos.co.uk/digitalguide/server/configuration/provide-raspberry-pi-with-a-static-ip-address/#:~:text=To%20assign%20an%20IP%20address,with%20the%20IPv4%20address%20192.168.
I am happy to delete this but thought I'd leave it here just in case someone had comments or found it useful. As per usual I answer my own question but sometimes just formalising my own ignorance into black and white is useful.
Related
Hi and good day to everyone.
I have been stuck on this problem for few days already and I really wish someone can help me in this.
I have an VIGI tp-link camera that I would like to stream from it using python. I know the IP of the camera, username password and port. Basically all the info I might need.
I tried using opecv but I could not stream.
I used the following code
import cv2, time
cap = cv2.VideoCapture("rtsp://admin:admin123#192.168.1.6:554")
cap.read()
but it is not working I tried to change to HTTP with port 80 which is the correct port but still no output. (Note this code worked for different types of IP cameras) I tried so many things really. I tried to use onvif python package https://github.com/FalkTannhaeuser/python-onvif-zeep and I could connect and use it to add change some configurations (I used port 80) , but I don't know how might this help to stream.
I could stream from VIGI software and I got all the information from there.
If I directly put the ip in the browser this message will show
No such file or directory
i got these ports from the VIGI software but none of them worked for me
I really wish someone can help me coz I run out of ideas already
I'm no Python user but I think what needs to be added in your RTSP path is /stream1 or /stream2.
I just got our C300HP-6 to do some testing. I tried to access it through RTSP via VLC but I couldn't seem to make it work. That was until I came upon their online manual.
With Port Forwarding enabled, you can remotely watch the videos with the URL rtsp://A.B.C.D:Port/streamN, for example, rtsp://10.0.1.47:28736/stream1. A.B.C.D is the WAN IP address of the gateway, and Port is the number of RTSP external port. N can be number 1 or 2 that indicates the stream, 1 for main stream and 2 for substream.
I have 2 Raspberry Pi 4 units.Both have been updated and upgraded and both flashed with rasbian lite. I created a really simply script, on the first raspi which connects to my pc on port 5999 and performs a basic function of grabbing the time and sending that on said port. My pc accepts it, prints it and writes it to a file. The second raspi has the exact same script with same permissions etc and the script does not work. No errors etc returned. I would for example run the server side on my pc, run the client side on the first raspi, works 100%, disconnect and run the same script on second raspi and no response on server side or client side. I have check "netstat -a"command, port listening etc on pc, have changed the port numbers on one and both raspis' but still cannot get the first raspi to send data.
Any similar experiences? Thank you in advance.
Problem solved, sorry guys, thx anyway for reply, omitted the 6 in the LAN IP address in the code on one of the raspberry Pi units.
If anyone wants the code then I will post, client and server working on PI4 units. Just let me know in comments.
I am desperatly trying to receive a HTTP call in RPI Python code.
My RPI is listening for HTTP on port 1234. I can succesfully hit this from another computer (on the same local network) by putting http://192.168.0.100:1234 (this is the PI's IP).
But if I try http://192.168.0.1:1234 then I get Connection Refused.
I have jumped through all kinds of hoops like setting up forwarding of port 1234 and I have even put 192.168.0.100 in DMZ on the router. Still I get Connection Refused.
I have tried this on 3 different kinds of routers to no avail. These routers are the kind where you have a WAN port.
Also I have tried to hit port 1234 from the Internet and that is still the same. I suppose that if this does not work locally then there is no hope of getting it to work from the Internet.
I am told that by default the RPI is not behind any kind of firewall so there for I strongly suspect the router.
Help me StackOverflow, you're my only hope:-)
Kind regards Martin
Thanks guys. I must have shot myself in the leg at some point. I am quite sure that I verified publicaddress:1234 at some point. But now it works so I am happy.
Kind regards Martin
I need to be able to connect to a raw serial connection that's connected to a modem.
The modem has an ip address and port.
This program works for one instance but is expensive for the amount of licenses I'd need and I'd prefer to code something:
http://www.serial-port-redirector.com/
It connects a remote ip to a local virtual com port.
I think it should be possible to do the same thing using pyserial but I'm struggling to understand how to do it.
This page kind of half explains it:
http://pyserial.sourceforge.net/examples.html#miniterm
But I'm still lost. If anyone could help me understand how to use rfc2217 in python it'd rock.
Thanks very much!
+anything for either linux/windows would be good.
For a class project I'm trying to do some socket programming Python but running into a very basic issue. I can't create a TCP connection from my laptop to a lab machine. (Which I'm hoping to use as the "server") Without even getting into the scripts I have written, I've been simply trying interpreter line commands with no success. On the lab machine (kh4250-39.cselabs.umn.edu) I type the following into Python:
from socket import *
sock = socket()
sock.bind(('', 8353))
sock.listen(5)
sock.accept()
And then on my laptop I type:
from socket import *
sock = socket()
sock.connect(('kh4250-39.cselabs.umn.edu', 8353))
At which point both machines block and don't do anything until the client times out or I send a SIGINT. This code is pretty much exactly copied from examples I've found online and from Mark Lutz's book Programming Python (using '' for the server host name apparently uses the OS default and is fairly common). If I run both ends in my computer and use 'localhost' for the hostname it works fine, so I suspect it's some problem with the hostnames I'm using on one or both ends. I'm really not sure what could be going wrong on such a simple example. Does anyone have an idea?
A good way to confirm whether it's a firewall issue or not is to perform a telnet from the command-line to the destination host in question:
% telnet kh4250-39.cselabs.umn.edu 8353
Trying 128.101.38.44...
And then sometime later:
telnet: connect to address 128.101.38.44: Connection timed out
If it just hangs there at Trying and then eventually times out, chances are the connection to the remote host on that specific port is being blocked by a firewall. It could either be at the network layer (e.g. a real firewall or a router access-list) or at the host, such as iptables or other host-based filtering mechanisms.
Access to this lab host might only be available from within the lab or the campus network. Talk with your professor or a network administrator or someone "in the know" on the network to find out for sure.
Try to bind the server to 'kh4250-39.cselabs.umn.edu' instead of '':
sock.bind(('kh4250-39.cselabs.umn.edu', 8353))
If this does not work: Another reason could be a firewall blocking the port 8353....