Can't stream tplink vigi camera using python - python

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.

Related

How can I access to the IP camera connected to a subnetwork of a router without port forwarding?

I'm struggling with some kind of connection problem.
Here's the problem that I wanted to resolve
What I want to do is getting video streaming data from a IP camera (RTSP)
The IP camera is attached to the router which has access to the internet
I want to connect to this IP camera from remote computer.
IP cam --- Router --- Internet --- My computer
I know that I can do this by setting port forwarding option of the router.
However, I cannot set the option because the router is not mine, which means I cannot access to the router's admininstration server (192.168.0.1)
I'm trying to figure out this issue by connecting a small edge computer (e.g., raspberry pi) to the router's subnetwork and send streaming data to my computer through the Internet.
IP cam --------- Router --- Internet --- My computer
minicomputer ---
It's certain that the minicomputer can access to my computer through ssh, so I think It's possible to use the minicom as a proxy.
What is the best the way to get the IP camera's streaming in my circumstance?
Please help.
I think a good idea would be to use a VPN. Install a VPN-Server (openvpn, wireguard, etc...) on your minicomputer in the same network as your camera. Than connect to your vpn from your computer. Now you should be able to access the camera.
I have a few ideas how to view the camera stream, depending how you would normaly access it.
If it is a software to connect to the camera, install a desktop-environment on your minicomputer and connect to it via VNC (more or less a linux equivalent to rdp on windows) or RDP. Then open the software and view your stream. It could be a bit laggy because it has to be transmitted two times (camera -> minipc -> your pc)
If you can access the stream via a url, you could setup a webserver (nginx or apache2) on your minicomputer and build a small html website, that displays the stream. This should be more perfomant than the first solution, but involves a bit more tinkering. If you should decide to use this solution, I should have an example HTML-Page somewhere. Just let me know and i will try to find it and share it.
Depending on how you setup your VPN-Server maybe you can connect to your Camera directly via it's IP. To do that, your VPN-Server has to do some routing between the subnets.
I know these are just some Ideas from the top of my head, but I hope I can help a bit. If you have more questions or I didn't explain it in a way it is understandable, feel free to ask again.

pyModbusTCP Raspberry Pi to PC connection eth0

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.

why do I get 2 ports when I portforward using ngrok

enter image description here
As you can see from the image above I'm given 2 ports what's the use of them? As I understood you only need 1 why am I given 2?
So turns out ngrok only opens a port while the application is open on a PC thus making it unusable I used portmap.io which gave me a free lifetime open port I recommend using that.

i am sending commands through serial port in python but they are sent multiple times instead of one

i am sending some commands having particular response serially using com port..the commands are kept in a file..i am reading each command through the file line by line and sending it serially over the com port..but when i am seeing it from the receiver end using Magic Terminal(Software)..i found that each command is going multiple times..which i am sending only one time..i have made a code in pycharm..and in the console i am seeing that command is going only once but from the uart receiving end the story is something else..i am stuck with this problem..i have maintain the same baudrate and everything but not able to diagnose the issue..
github link for the code is: https://github.com/AkshatPant06/Akshat-Pant/blob/master/cmd%20list
def recvResponse():
ser.write(serial.to_bytes(intCmd))
time.sleep(1)
data_recv=ser.read(2)
return data_recv
this i have used to receive the 2 byte response..
There seems to be nothing wrong with your code. At least to the extent I could reproduce, it only sends the command once (I tried your function after setting up my serial port in loopback).
I cannot say for sure but it might be that the terminal you're using has two windows, one for input and another one for output and somehow you're getting confused with what is in and out of your port.
One easy way to deal with this kind of issue is to use a sniffer on your port. You can do that combining com0com and Termite on Windows, as I recently explained here.
As you can see there is only one window on this terminal, and after setting up the forwarding you'll everything that comes in and out of your port. That should make it easier to see what your code is writing and reading.
To give you a conventional scenario to apply the sniffer trick you can refer to the following screenshot:
In this case, we have two real serial ports on a computer. On the first (COM9) we are running a Modbus server (you can imagine it as a bunch of memory addresses, each of one storing a 16-bit number). On COM10 we have a client that is sending queries asking for the contents of the first 10 addresses (called registers using the Modbus terminology). In a general use case, we have those ports linked with a cable, so we know (theoretically) that the client on COM10 is sending a data frame asking for those ten registers and the server on COM9 is answering with the numbers stored on those registers. But we are only able to see the contents on the server (left side of the picture) and what the client is receiving (right). What we don't see is what is traveling on the bus (yeah, we know what it is, but we don't know exactly how the Modbus protocol looks like on the inside).
If we want to tap on the bus to see what is being sent and received on each side we can create a couple of virtual ports with com0com and a port forwarding connection with Termite, something like the following screenshot:
Now we have moved our Modbus server to one of the virtual serial ports (COM4 in this case). After installing com0com we got (by default, but you can change names or add more port pairs, of course) a pair of forwarded ports (COM4<-->COM5). Now, if we want to see what is circulating through the ports we open Termite (bottom-right side of the picture) and set up another port forwarding scheme, in this case from virtual port COM5 to the real port COM9.
Finally (and exactly the same as before we were sniffing), we have COM9 connected together with COM10 with a cable. But now we are able to see all data going to and fro on the bus (all those HEX values you see on Termite displayed with the green/blue font).
As you can see, this will offer something similar to what you can do with more professional tools.

How to send raw string to a dotmatrix printer using python in ubuntu?

I have a dot-matrix printer LX-300 connected to my computer through the network. How do I send a raw string with ESCP characters directly to my printer in Python?
The computer is connected to the printer through another computer. I need to send a raw string because LX-300 image printing result is blurry.
The Problem
To send data down this route:
Client computer ---> Server (Windows machine) ---> printer (dot-matrix)
...and to not let Windows mess with the data; instead to send the raw data, including printer control codes, straight from the client computer.
My Solution
Here's how I solved a near-identical problem for a small in-house database application:
Step 1) Make the printer network-accessible without Windows getting its fingers in the data routed to it. I accomplished this by installing the printer using the "Generic/Text Only" driver, then installing
RawPrintServer on the Windows machine connected to the printer.
Step 2) Send raw data over the network to the TCP/IP port specified when you set up RawPrintServer (default is 9100). There are various ways to do that, here's what I did:
data = b"\x1B#A String To Print\x1B#" # be sure to use the right codes for your printer
ip_addr = 123.123.123.123 # address of the machine with the printer
port = 9100 # or whatever you set it to
s = socket.socket()
try:
s.connect((ip_addr, port))
s.send(data)
except:
# deal with the error
finally:
s.close()
Background
I thought about the problem in two parts:
Client machine: spitting out the data I need from Python with the correct formatting/control codes for my printer, and sending it across the network
Print server machine: transmitting the data to the locally connected printer
Number 1 is the easy part. There are actually some libraries in PyPI that may help with all the printer codes, but I found most of them are aimed at the little point-of-sale label printers, and were of limited use to me. So I just hard-coded what I needed into my Python program.
Of course, the way you choose to solve number 2 will effect how you send the data from Python. I chose the TCP/IP route to avoid dealing with Samba and Windows print issues.
As you probably discovered, Windows normally tries very hard to convert whatever you want to print to a bitmap and run the printer in graphics mode. We can use the generic driver and dump the data straight into the (local) printer port in order to prevent this.
The missing link, then, is getting from the network to the local printer port on the machine connected to the printer. Again, there are various ways to solve this. You could attempt to access the Windows printer share in some way. If you go the TCP/IP route like I did, you could write your own print server in Python. In my case, the RawPrintServer program "just worked" so I didn't investigate any further. Apparently all it does is grab incoming data from TCP port 9100 and shove it into the local printer port. Obviously you'll have to be sure the firewall isn't blocking the incoming connections on the print server machine. This method does not require the printer to be "shared" as far as Windows is concerned.
Depending on your situation (if you use DHCP), you might need to do some extra work to get the server's IP address in Python. In my case, I got the IP for free because of the peculiarity of my application.
This solution seems to be working out very well for me. I've got an old Panasonic printer running in Epson ESC/P compatibility mode connected to a Windows 7 machine, which I can print to from any other computer on the local network. Incidentally, this general idea should work regardless of what OS the client computer is running.
Ultimately, you will need and want to write your own wrapper/script to do this. And since you are using a distribution of Linux, this is relatively easy.
On a Linux OS, the simplest way to issue a print job is to open a subprocess to the lpr. Generally, using lpr lets you access the printer without the need to be logged in as root (being a superuser), which is desirable considering the amount of damage that can be done while logged in as a "superuser".
Code like the following:
import subprocess
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(data_to_send_to_printer)
Should be a good jumping off point for you. Essentially, this code should allow you to accomplish what you need.
Be careful though; depending on your privilege levels, a call to open a subprocess might need root level/Superuser permissions.
Subprocesses generally inherit the User IDs and access rights by the user that is running the command. For example, if the subprocess is created by a root user, then you will need root user/Superuser rights to access that subprocess.
For more information, check out the hyperlinks I've included in the post.
Good luck!

Categories