BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Intermittent failing when calling blynk to write to V5 (Using Python)

Any ideas?

I am writing with Python 2.7 and call a my function :

pin = “V5”
val = str(scankWh)
write_pin(pin, val)

Its failing intermittently with

  File "/home/pi/python_programs/jacobproductionnewrelaytest04012018.py", line 1289, in write_pin
    r = requests.put(BLYNK_URL+BLYNK_AUTH+'/update/'+pin, data=put_body, headers=put_header)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 105, in put
    return request('put', url, data=data, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 407, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

john

My function I call:

def write_pin(pin, val):
    print pin, val
    put_header={"Content-Type": "application/json"}
    put_body = json.dumps([val])
    print put_body
    
    r = requests.put(BLYNK_URL+BLYNK_AUTH+'/update/'+pin, data=put_body, headers=put_header)
    if r.status_code != 200:
        print v + ": FAILED\n"
    else:
        print "OK\n"

Does BLYNK_URL terminate with the required /

I have it set as:

BLYNK_AUTH = ‘273d9020516144038ad533157XXXXXXc’
BLYNK_URL = ‘http://blynk-cloud.com/

is that wrong?

Looks good to me.

An intermittent problem suggests it may not be a coding problem.

A few days ago some numpties severed two of the main subsea cables providing internet access to our island. It basically took us to sub 56K modem speeds with long ping times. Many iOT systems will not work at this level of service and same applies if you are using GPRS etc.

Its been running for the last 6 hours writing to V3,V4,V5 & V6 with no error

Any ideas why its failing?

Just seen your note, that would make sense. Any idea when it back to full speed?

@Johnuready the island in question is not the UK, it’s a small island near Syria. Looks like ISP’s on the island have switched to other systems or the cables have been repaired, back to 20MB / 3MB and 100ms to UK servers which is pretty good for here.

I am still intermittently getting a failure when writing to my V pin. Do you still have problems with the internet speed to your servers?

Since Blynk for Python is in Alpha stage, and aside from that announcement we haven’t heard much more… perhaps expecting full functionality is a bit much? :stuck_out_tongue_winking_eye:

There were never any issues with the Blynk servers.

The problems were specific to me and others living on our small island.

It takes time for those TCP IP packet carrying bottles and coconuts to float back and forth from the mainland :stuck_out_tongue:

@Johnuready the post above was simply pointing out that Blynk and other iOT networks will not work with poor internet connections. Nothing to do with the Blynk servers that are distributed around the globe.

Ironically a few days before the cables were severed there was an announcement in the local Press that the 5TB cables were going to be replaced with 160TB cables in the next few years at a cost of approx $350m. We went down to about 0TB for a few days.

1 Like

I am still having very intermittent problems sending information to V pins from my Python Program using the method I described. I looked for other ways and found the example below in the examples library:

I am now struggling how to include this into my program without blynk.run()

Anybody help please?

import BlynkLib
import time

BLYNK_AUTH = ‘YourAuthToken’

Initialize Blynk

blynk = BlynkLib.Blynk(BLYNK_AUTH)

Register Virtual Pins

@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
print(‘Current V1 value: {}’.format(value))

@blynk.VIRTUAL_READ(2)
def my_read_handler():
# this widget will show some time in seconds…
blynk.virtual_write(2, time.ticks_ms() // 1000)

Start Blynk (this call should never return)

blynk.run()