Created
February 6, 2020 19:24
-
-
Save micw/202f9dee5c990f0b0f7e7c36b567d92b to your computer and use it in GitHub Desktop.
Getting camera images from esp32cam with esphome and python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import aioesphomeapi | |
import asyncio | |
async def main(): | |
loop = asyncio.get_running_loop() | |
cli = aioesphomeapi.APIClient(loop, "HOST-OR-IP", 6053, "API-PASSWORD-OR_EMPTY") | |
await cli.connect(login=True) | |
def cb(state): | |
if type(state) == aioesphomeapi.CameraState: | |
try: | |
with open('out/x.jpg','wb') as out: | |
out.write(state.image) | |
print("Image written") | |
except Exception as e: | |
print(e) | |
await cli.subscribe_states(cb) | |
l = await cli.list_entities_services() | |
print(l) | |
loop = asyncio.get_event_loop() | |
try: | |
asyncio.ensure_future(main()) | |
loop.run_forever() | |
except KeyboardInterrupt: | |
pass | |
finally: | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The member of
CameraState
in which to find the image is calleddata
, notimage
. If you writeit should work