-
-
Save mgottholsen/d2ecc2889d5adf7ea093aa67801f6aad to your computer and use it in GitHub Desktop.
Getting camera images from esp32cam with esphome and python
This file contains 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