fronzbot / blinkpy

A Python library for the Blink Camera system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blink Mini don't work, Blink Ourdoor works (with minor Problem)

MarkusKress opened this issue · comments

Hello.
I have three Problems using the Library (Version blinkpy-0.19.0 without HA):

1.) Camera Type Mini does not work.
2.) Warnings "Could not extract camera info" with all Cameras.
3.) Timing between camera.snap_picture and camera.image_to_file

This is my Test-Script:

auth = Auth({"username": "xxxx@yyy.de", "password": "ABC"}, no_prompt=True)
blink.save("blink.credentials")
blink.auth = auth
blink.start()
camera = blink.cameras['Werkstatt']
#camera = blink.cameras['Hof']
camera.snap_picture()
blink.refresh()
time.sleep(3)
camera.image_to_file('/var/www/html/x.jpg')

First Problem:
Cameras of Type Outdoor working (with some Warnings), but with Cameras of Type Mini I've got no Picture. Running the Script with 'Werkstatt' (Type Mini), I've got these Errors:

Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Traceback (most recent call last):
  File "./blink.py", line 35, in <module>
    camera.image_to_file('/var/www/html/x.jpg')
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/camera.py", line 239, in image_to_file
    response = self.get_media()
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/camera.py", line 119, in get_media
    timeout=TIMEOUT_MEDIA,
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/api.py", line 315, in http_get
    is_retry=is_retry,
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/auth.py", line 195, in query
    req = self.prepare_request(url, headers, data, reqtype)
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/auth.py", line 91, in prepare_request
    return req.prepare()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 267, in prepare
    hooks=self.hooks,
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 390, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?

Second Problem:
These warnings occurs also when using a Camera of Type "Outdorrs", but Picture is taken:

Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown

Third Problem:
Without "time.sleep(3)" I've got only an old Snapshot. It seems the "camera.image_to_file" is too fast.
I think camera.snap_picture() is asycron (blink servers has to send the command to camera in you home network) and it needs some time before getting the picture.

It looks like the library is unable to find your camera. You'll need to debug that and figure out what's happening: list out all cameras, make sure yours is there. If so, check attributes, etc.

I can confirm Mini cameras work find on my end, so it's not a generic "Mini cameras are broken" issue.

I'm so glad that to hear Mini are working. I tried it also using the api calls from MattTW/BlinkMonitorProtocol with curl to find out what's wrong. But I run into the same problem. I tried debugging for hours and didn't find the problem. I'm sure the Name is correct, I tried also with other Blink Cameras I have. I've checked all twice, also Blanks or upper and lower case Letters.

The json of Homescreen shows the Outdoor cameras are below "Cameras", the Mini below "Owls".

Here the Parts for Account, Networks and Sync Module of the Homescreen:

{
  "account": {
    "id": 16YYY,
    "email_verified": true,
    "email_verification_required": false,
    "amazon_account_linked": false
  },
  "networks": [
    {
      "id": 16ZZZ,
      "created_at": "2020-12-01T17:56:15+00:00",
      "updated_at": "2022-04-12T06:12:00+00:00",
      "name": "Markus und Siggi zuhause",
      "time_zone": "Europe/Berlin",
      "dst": true,
      "armed": true,
      "lv_save": false
    }
  ],
  "sync_modules": [
    {
      "id": 23DD99,
      "created_at": "2021-07-06T16:55:15+00:00",
      "updated_at": "2022-04-12T06:10:36+00:00",
      "onboarded": true,
      "status": "online",
      "name": "My Blink Sync Module",
      "serial": "G8T1LPFFF4023S6S",
      "fw_version": "4.4.8",
      "type": "sm2",
      "subtype": "vinnie",
      "last_hb": "2022-04-12T10:17:45+00:00",
      "wifi_strength": 5,
      "network_id": 16ZZZ,
      "enable_temp_alerts": true,
      "local_storage_enabled": false,
      "local_storage_compatible": true,
      "local_storage_status": "active",
      "revision": "00"
    }
  ],

Here one Outdoor Camera:

  "cameras": [
    {
      "id": 23AA79,
      "created_at": "2021-07-26T08:17:07+00:00",
      "updated_at": "2022-04-12T10:14:15+00:00",
      "name": "Hof",
      "serial": "G8T1GJ000ABCAUGT",
      "fw_version": "10.56",
      "type": "catalina",
      "enabled": false,
      "thumbnail": "/api/v3/media/accounts/16YYY/networks/16ZZZ/catalina/23AA79/thumbnail/thumbnail.jpg?ts=1649753180&ext=",
      "status": "done",
      "battery": "ok",
      "usage_rate": false,
      "network_id": 16ZZ7,
      "issues": [],
      "signals": {
        "lfr": 1,
        "wifi": 3,
        "temp": 65,
        "battery": 3
      },

Here the Mini:

  "owls": [
    {
      "id": 19XX99,
      "created_at": "2021-06-29T13:38:15+00:00",
      "updated_at": "2022-04-12T08:18:46+00:00",
      "name": "Werkstatt",
      "type": "owl",
      "onboarded": true,
      "serial": "G8T194DEF1731XEF",
      "fw_version": "9.78",
      "enabled": true,
      "thumbnail": "/api/v3/media/accounts/16YYY/networks/16ZZZ/owl/19XX99/thumbnail/thumbnail.jpg?ts=1649751526&ext=",
      "status": "online",
      "network_id": 16ZZZ,
      "local_storage_enabled": false,
      "local_storage_compatible": true,
      "snooze": false,
      "snooze_time_remaining": null,
      "revision": "00"
    },

This is the Rest Call for new thumbnail which failed with :

curl --request POST --url "https://rest-e004.immedia-semi.com/network/16ZZZ/camera/19XX99/thumbnail" --header "TOKEN_AUTH: 6BX8_yvBzqFuu1la3xMsdwe"

Here the response:

{
  "message": "Camera not found",
  "code": 500
}

With the response of Login I got

"tier": "e004"

So I use for URL https://rest-e004.immedia-semi.com

Rather than the rest call (which appears incorrect to me), can you just try the following via the library (after logging in, etc):

for name, camera in blink.cameras.items():
  print(f"{name}: {camera}")
  print(f"{camera.attributes}")
  print("----------")

This will print the camera instance for everything found along with a list of attributes.

Here the Output for the Mini:

Werkstatt: <blinkpy.camera.BlinkCameraMini object at 0x7fc782351198>
{'name': 'Werkstatt', 'camera_id': '19XX99', 'serial': 'G8T194ABCABC1XEF', 'temperature': None, 'temperature_c': None, 'temperature_calibrated': None, 'battery': None, 'battery_voltage': None, 'thumbnail': 'https://rest-e004.immedia-semi.com/api/v3/media/accounts/16YYY/networks/16ZZZ/owl/19XX99/thumbnail/thumbnail.jpg?ts=1649751526&ext=', 'video': None, 'motion_enabled': True, 'motion_detected': False, 'wifi_strength': None, 'network_id': 16ZZZ, 'sync_module': 'Markus und Siggi zuhause', 'last_record': None, 'type': 'owl'}

Seems ok.

Hi,

a had almost the same problem with the timing, try instead:
time.sleep(10) blink.refresh(force=True)

Hi,

a had almost the same problem with the timing, try instead: time.sleep(10) blink.refresh(force=True)
Triggering a Snapshot is an asyncon command. You have to poll the API for the command has been finished and then you can get the thumbnail. Or waiting some time and hope the snapshot is ready for download. The time depends on speed of camera wifi signal, you internet connection and the response time of the blink cloud. For me it's about 3 seconds.

@MarkusKress did you try what he suggested? Specifically the force=True argument to blink.refresh?

Yes, I tried also:

blink.auth = auth
blink.start()
camera = blink.cameras['Outdoor Neu']
camera.snap_picture()
blink.refresh(force=True)
camera.image_to_file('/var/www/html/x.jpg')

And it's still the picture before last camera.snap_picture(). Only waiting some seconds (2 sec is too less, 3 sec works most time for me).

Very Interessting: I've got for my 5 Mini this messages:

Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown`

But if I add a time.sleep(4) between blink.start() and camera.snap_picture(), these errors disappears:

blink.auth = auth
blink.start()
camera = blink.cameras['Outdoor Neu']
time.sleep(4)
camera.snap_picture()
blink.refresh(force=True)
camera.image_to_file('/var/www/html/x.jpg')

And the Mini works now if I put the time.sleep(4)

I tried a shorter time.sleep(3) and it doesn't work anymore for Mini:

blink.auth = auth
blink.start()
camera = blink.cameras['Outdoor Neu']
time.sleep(3)
camera.snap_picture()
blink.refresh(force=True)
camera.image_to_file('/var/www/html/x.jpg')

Here the output using time.sleep(3):

Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Could not extract camera info: {'message': 'Camera not found', 'code': 500}
Could not find thumbnail for camera unknown
Traceback (most recent call last):
  File "./blink.py", line 36, in <module>
    camera.image_to_file('/var/www/html/x.jpg')
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/camera.py", line 239, in image_to_file
    response = self.get_media()
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/camera.py", line 119, in get_media
    timeout=TIMEOUT_MEDIA,
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/api.py", line 315, in http_get
    is_retry=is_retry,
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/auth.py", line 195, in query
    req = self.prepare_request(url, headers, data, reqtype)
  File "/usr/local/lib/python3.7/dist-packages/blinkpy/auth.py", line 91, in prepare_request
    return req.prepare()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 267, in prepare
    hooks=self.hooks,
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 390, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?

Seems it's race condition. This sloves the Problem for my Minis, but still the the picture before last camera.snap_picture(). So I've added the second time.sleep(3) (3 Seconds seems enough between snap_picture and image_to_file for me":

blink.auth = auth
blink.start()
camera = blink.cameras['Outdoor Neu']
time.sleep(4)
camera.snap_picture()
blink.refresh(force=True)
time.sleep(3)
camera.image_to_file('/var/www/html/x.jpg')

Now it works with Mini and I've got the last Snapshot. The blink.refresh(force=True) is not nessesary, also blink.refresh().

This works for both Problems (I'll add 1 or 2 seconds to both time.sleep):

blink.auth = auth
blink.start()
camera = blink.cameras['Outdoor Neu']
time.sleep(4)
camera.snap_picture()
time.sleep(3)
camera.image_to_file('/var/www/html/x.jpg')

I've tested more and tried to put the time.sleep(4) before blink.start() and it seems it works too. Then I removed the time.sleep(4) again and it works now without time.sleep(4).
During my tests, I switched several times between with and without time.sleep(4) and the error was reproduceable if I don't use time.sleep(4). Now I can't Login anymore:

Login endpoint failed. Try again later.
Cannot setup Blink platform.

Seems I've tested too much.

Why does my Minis now working? Did I make some mistakes? Wrong sequence or something else? Is my problem to login each time I make a snapshot?

You have the sleep in the wrong spot. It needs to be between snap picture and refresh. The refresh grabs the image that was snapped and stores it in memory. Putting a delay between refresh and image_to_file is not needed

To be clear:

blink.start()
camera = ...
camera.snap_picture()
time.sleep(5)
blink.refresh(force=True)
camera.image_to_file(...)

Is what you need. Any timeouts you experience are from hammering the servers too hard. Just wait and they should clear up

Do you think it solves both problems (I can't test it anymore, until this client is blocked)?

Yes, it solves both problems I had.

Good to hear! I'll close this issue out then