Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Binary Protocol (non-json commands) #3

Open
devbis opened this issue Mar 16, 2025 · 34 comments
Open

Support for Binary Protocol (non-json commands) #3

devbis opened this issue Mar 16, 2025 · 34 comments

Comments

@devbis
Copy link
Owner

devbis commented Mar 16, 2025

Optionally: create virtual env if not in docker:

python3 -m venv venv
. venv/bin/activate

Install/upgrade the library from the latest commits in the branch:

pip3 install -U --no-cache-dir --force-reinstall https://github.com/devbis/aiopppp/archive/refs/heads/binary-proto.zip
python3 -m aiopppp -a 255.255.255.255 -u admin -p admin --log-level DEBUG
@mabusdogma
Copy link

I want to help, I just don't know how or where to install this, I have one raspberry with HA, one Windows laptop ...and almost zero experience on Linux.

Can I do this on windows? I tried to find out more and it looks like I can use Windows, but I need to install Python first... Am I going in the right direction?

@mabusdogma
Copy link

Ok! I think I've got it, I did it on windows, and I get a message, mostly an error:

python -m aiopppp -a 255.255.255.255

DEBUG:asyncio:Using proactor: IocpProactor
INFO:aiopppp.discover:Start discovery on 255.255.255.255:32108
INFO:aiopppp.http_server:Starting web server on port 4000
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
INFO:aiopppp.http_server:Shutting down web server
DEBUG:aiopppp.discover:Received PunchPkt: [DevID(BATE-692065-IURQM)] from ('192.168.1.163', 32108)
INFO:aiopppp.discover:found device DevID(BATE-692065-IURQM)
DEBUG:aiopppp.session:send> PunchPkt: [DevID(BATE-692065-IURQM)]
DEBUG:aiopppp.session:send> P2pRdy: [DevID(BATE-692065-IURQM)]
DEBUG:aiopppp.session:Session main task cancelled, sending close packet
DEBUG:aiopppp.session:send> Close: []
INFO:aiopppp.discover:Stop discovery
WARNING:aiopppp.packets:Invalid pkt length: pkt.len=20, real length=28, [f1 42 00 14 42 41 54 45 00 00 00 00 00 0a 8f 61 49 55 52 51 4d 00 00 00 00 00 00 00 00 00 00 00]
DEBUG:aiopppp.session:recv< PacketType.P2pRdy, len=28
Traceback (most recent call last):
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\__main__.py", line 29, in amain
    await asyncio.gather(discovery.discover(on_device_found), start_web_server())
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\http_server.py", line 133, in start_web_server
    await site.start()
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiohttp\web_runner.py", line 121, in start
    self._server = await loop.create_server(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\asyncio\base_events.py", line 1596, in create_server
    _set_reuseport(sock)
    ~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\asyncio\base_events.py", line 91, in _set_reuseport
    raise ValueError('reuse_port not supported by socket module')
ValueError: reuse_port not supported by socket module

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\__main__.py", line 61, in <module>
    main()
    ~~~~^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\__main__.py", line 57, in main
    asyncio.run(amain(remote_addr=args.addr, local_port=args.local_discovery_port))
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\asyncio\base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\__main__.py", line 32, in amain
    session.stop()
    ~~~~~~~~~~~~^^
  File "C:\Users\Bob\AppData\Local\Programs\Python\Python313-32\Lib\site-packages\aiopppp\session.py", line 324, in stop
    raise RuntimeError('Session is not started')
RuntimeError: Session is not started

@devbis
Copy link
Owner Author

devbis commented Mar 17, 2025

@mabusdogma Hi, thanks for logs. I removed reuse_port for http server. Can you please install and run it again with the same commands?

@mabusdogma
Copy link

Now it works! Still no image, but getting better...

python -m aiopppp -a 255.255.255.255

DEBUG:asyncio:Using proactor: IocpProactor
INFO:aiopppp.discover:Start discovery on 255.255.255.255:32108
INFO:aiopppp.http_server:Starting web server on port 4000
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.discover:Received PunchPkt: [DevID(BATE-692065-IURQM)] from ('192.168.1.163', 32108)
INFO:aiopppp.discover:found device DevID(BATE-692065-IURQM)
DEBUG:aiopppp.session:send> PunchPkt: [DevID(BATE-692065-IURQM)]
DEBUG:aiopppp.session:send> P2pRdy: [DevID(BATE-692065-IURQM)]
WARNING:aiopppp.packets:Invalid pkt length: pkt.len=20, real length=28, [f1 42 00 14 42 41 54 45 00 00 00 00 00 0a 8f 61 49 55 52 51 4d 00 00 00 00 00 00 00 00 00 00 00]
DEBUG:aiopppp.session:recv< PacketType.P2pRdy, len=28
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []
...
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []
DEBUG:aiopppp.session:recv< PacketType.P2PAlive, len=0
DEBUG:aiopppp.session:send> P2PAliveAck: []

Image

@devbis
Copy link
Owner Author

devbis commented Mar 18, 2025

@mabusdogma Cool. I rewrote waiting for camera readiness, please, check out the new version.

@mabusdogma
Copy link

mabusdogma commented Mar 18, 2025

Image
Well this time I don't see any buttons in localhost:4000, it looks like it's on a loop, waiting for an image...

@devbis
Copy link
Owner Author

devbis commented Mar 18, 2025

Camera is not responding to the initial packet. You may need to repower it

@mabusdogma
Copy link

Ok, so far I've got this:

Image

I'll try to repower it many times, just in case I can get something else. Still no image in localhost:4000.

Should I have an image? Or this is going as expected?

@devbis
Copy link
Owner Author

devbis commented Mar 19, 2025

At some point camera disconnects (sends Close packet).
Maybe because of incomplete process on my side.
I added more logging. Can you please run the new code and provide logs in text format to see camera responses?

And does your camera work with cam-reverse project? Does it show image?
because I'm trying to re-implement the same flow.

@mabusdogma
Copy link

bob.txt
There's a txt file with the logs, I tried to do different things (reconnect, stop the program, un plug and plug the camera and so on...).

I'm afraid this camera it doesn't work with cam-reverse

@devbis
Copy link
Owner Author

devbis commented Mar 22, 2025

@mabusdogma Hi, your log was very helpful.

I implemented an emulator that responds commands similar to A9 cams. And fixed several issues in binary protocol code.

Can you please run the code again along with capturing logs to let me fix issues.

@mabusdogma
Copy link

bob.txt
Image
It looks like it needs the Android app to be running, if I stop it, or even if the phone screen goes off (in one minute, usually), I get an error on Python. There are some examples of that in the logs.

@devbis
Copy link
Owner Author

devbis commented Mar 23, 2025

Thanks! It looks your response for DevStatus is empty. I fixed parsing in the new revision.

Do you know your camera's credentials? If uses admin:admin by default. And I don't know if the camera responds with "invalid password" as the protocol is unclear.

Anyway, another run should give us more information on starting video. And please, check login and password for the camera

UPD: I added parameters to provide credentials in cli. If you know your credentials, please, use them:

python3 -m aiopppp -a 255.255.255.255 -u admin -p admin --log-level DEBUG

@mabusdogma
Copy link

bob.txt

Image
Image

It looks it's user:6666
It works!!!!! :)
For a moment I can see an image, but it suddenly fades away (2 images attached)

@mabusdogma
Copy link

Checked once again in a windows web browser and I've got video! It looks like the still image that fades away only occurs in a phone browser :)

@devbis
Copy link
Owner Author

devbis commented Mar 24, 2025

@mabusdogma With achieved result I rewrote the code for readability. But the logic is the same.
Can you please check it again? If it is working, I'll prepare a new version and make a release to add this cameras to HA component.

Can you also check reboot button. It should do something like camera rebooting.

@mabusdogma
Copy link

mabusdogma commented Mar 24, 2025

Image
bob.txt
Not sure if i did everything right, I tried to plug/unplug, check on Windows, Android... But after several attempts I couldn't get a video on the browser, only in the ysxlite app.
I tried every button, including rebooting, but since I didn't get an image I'm not sure if it works.

@devbis
Copy link
Owner Author

devbis commented Mar 24, 2025

It seems, tickets are not working for your cam or I don't understand the code in cam-reverse.
Tried to revert previous data generation with zeroes in ticket.
Please, run again.

@shlomicthailand
Copy link

@devbis - i fail for authentication although i tried with and without user/pass

DEBUG:aiopppp.session:recv< PacketType.Drw, len=24
DEBUG:aiopppp.session:handle_drw(idx=0, chn=Channel.Command)
DEBUG:aiopppp.session:send> DrwAck: [d1 00 00 01 00 00]
DEBUG:aiopppp.session:handle_incoming_command_packet: token=00000000, BinaryCommands.ConnectUserAck data=ff 00 00 00 79 42 77 39
DEBUG:aiopppp.session:Got command result b'\xff\x00\x00\x00yBw9'
DEBUG:aiopppp.session:Connect user responded with auth_result=b'\xff\x00\x00\x00yBw9'
INFO:aiopppp.session:Stopping task for DevID(TBAT-551800-OBWVA)
INFO:aiopppp.discover:Stop discovery
INFO:aiopppp.http_server:Shutting down web server
Traceback (most recent call last):
  File "/Users/shlomic/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/shlomic/.pyenv/versions/3.10.13/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/shlomic/.pyenv/versions/pppp_cam/lib/python3.10/site-packages/aiopppp/__main__.py", line 116, in <module>
    main()
  File "/Users/shlomic/.pyenv/versions/pppp_cam/lib/python3.10/site-packages/aiopppp/__main__.py", line 107, in main
    asyncio.run(amain(
  File "/Users/shlomic/.pyenv/versions/3.10.13/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/shlomic/.pyenv/versions/3.10.13/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/shlomic/.pyenv/versions/pppp_cam/lib/python3.10/site-packages/aiopppp/__main__.py", line 59, in amain
    await asyncio.gather(*done)
  File "/Users/shlomic/.pyenv/versions/pppp_cam/lib/python3.10/site-packages/aiopppp/session.py", line 295, in _run
    await self.setup_device()
  File "/Users/shlomic/.pyenv/versions/pppp_cam/lib/python3.10/site-packages/aiopppp/session.py", line 726, in setup_device
    raise AuthError(f'Login failed: [{auth_result.hex(" ")}]')
aiopppp.exceptions.AuthError: Login failed: [ff 00 00 00 79 42 77 39]

does the cam need to be already connected to wifi - or in access point mode ?

@devbis
Copy link
Owner Author

devbis commented Mar 24, 2025

It should be connected to WiFi already.

If your l camera works with cam reverse, you need to use credentials admin:admin

@mabusdogma
Copy link

Alternatively, it can be admin:6666

@shlomicthailand
Copy link

shlomicthailand commented Mar 24, 2025

@devbis - the cam is connected to Wifi (tried both the original app YsxLite and cam-reverse) but it does not seems the camera respond to the broadcast events.

python3 -m aiopppp -a 255.255.255.255 -u admin -p admin
DEBUG:asyncio:Using selector: KqueueSelector
INFO:aiopppp.discover:Start discovery on 255.255.255.255:32108
INFO:aiopppp.http_server:Starting web server on port 4000
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)
DEBUG:aiopppp.discover:broadcast> f1 30 00 00
DEBUG:aiopppp.discover:broadcast> 2c ba 5f 5d
DEBUG:aiopppp.discover:sending discovery message ('255.255.255.255', 32108)

@devbis
Copy link
Owner Author

devbis commented Mar 24, 2025

@shlomicthailand the camera must be disconnected from other apps, like mobile app or cam-reverse. Re-power it if needed

@devbis
Copy link
Owner Author

devbis commented Mar 24, 2025

@mabusdogma is it fixed with the latest updates for your camera?

@shlomicthailand
Copy link

@shlomicthailand the camera must be disconnected from other apps, like mobile app or cam-reverse. Re-power it if needed

@devbis i lost you , i thought you said it should be already paired , that can be only with app or cam-reverse. so what do you say should be the steps ?

@devbis
Copy link
Owner Author

devbis commented Mar 25, 2025

The camera should be connected to the WiFi router. But no other apps should be running at the same time, as these cameras support single connection only.

@mabusdogma
Copy link

@mabusdogma is it fixed with the latest updates for your camera?

Sorry, I'm out of town for a few days, I'm back on thursday

@devbis
Copy link
Owner Author

devbis commented Mar 26, 2025

It looks like the camera works with the latest updates. I released both the library and the HA component with this protocol.
Please, check out pppp_camera version 1.1.0

@mabusdogma
Copy link

@mabusdogma is it fixed with the latest updates for your camera?

Hello again, I'm afraid it doesn't work for my camera, I can install the integration with no errors, but I can't get any video/audio :(

I'll try to reinstall the app and then I'll check again.

Image
Image

@devbis
Copy link
Owner Author

devbis commented Mar 28, 2025

Can you please run the command with library again and send logs?

pip3 install -U --no-cache-dir --force-reinstall https://github.com/devbis/aiopppp/archive/refs/heads/binary-proto.zip
python3 -m aiopppp -a 255.255.255.255 -u admin -p admin --log-level DEBUG

@mabusdogma
Copy link

mabusdogma commented Mar 28, 2025

Can you please run the command with library again and send logs?

pip3 install -U --no-cache-dir --force-reinstall https://github.com/devbis/aiopppp/archive/refs/heads/binary-proto.zip
python3 -m aiopppp -a 255.255.255.255 -u admin -p admin --log-level DEBUG

bob2.docx

Image
Image

When I run the Python command on windows CMD, I can see video in a browser, using localhost, but I can't see any video or image somewhere else (another PC or a phone) using host's IP.

Just in case, I reinstalled the integration on HA, but still no luck getting video.

@devbis
Copy link
Owner Author

devbis commented Mar 28, 2025

@mabusdogma For the HA component, did you use exact IP for configuration? 192.168.1.163 ?

To collect logs in HA you need to edit its configuration.yaml to add more logging:

logger:
  logs:
    custom_components.pppp_camera: debug
    aiopppp: debug

@mabusdogma
Copy link

@mabusdogma For the HA component, did you use exact IP for configuration? 192.168.1.163 ?

To collect logs in HA you need to edit its configuration.yaml to add more logging:

logger:
logs:
custom_components.pppp_camera: debug
aiopppp: debug

error_log.docx
I hope it helps :)

@devbis
Copy link
Owner Author

devbis commented Mar 31, 2025

According to logs it starts video and collects frames.
Did you try to create a picture entity in your Lovelace UI with camera device as the source?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@shlomicthailand @devbis @mabusdogma and others