Working with HTTP RESTapi - PUT

Hello Blynk. At this time, im working in a project using the “Blynk HTTP RESTful API” with the write pin value using PUT.
It works fine with my auth token and value. All tools are in this link

Now, im trying to sent a “test” value inside the request text using this code

from urllib2 import Request, urlopen

test = 15

values = """

headers = {
  'Content-Type': 'application/json'
request = Request('', data=values, headers=headers)
request.get_method = lambda: 'PUT'

response_body = urlopen(request).read()
print response_body

but i get the error: “object of type ‘int’ has no len()”

Im using a raspberry pi 3 board and i do this because i want to update this “test” value which comes from an arduino board via I2C.

Could you give me som advice to use PUT request properly? Best regards

I always recommend using the GET syntax for updating pins. Blynk allows GET in addition to PUT for updates and you can put all the parameters in the url without using the body. Check the docs for the precise syntax.

What type of widget are you sending the value 15 to?

If it’s a button you would have change to normal 0 to 1 parameters in the widget.

Thank you for your quick response

Im using a value display widget, this value comes from arduino via I2C to raspberry using python code.

please could you help me with the right way to insert “pin” and “value” fields to get updates from my “test” value which comes from arduino?

from urllib2 import Request, urlopen

request = Request(’’)

response_body = urlopen(request).read()
print response_body


OK let’s assume this is on V1.

If you enter this in a browser what does it return?

I use this command and it works pretty well in V4, i attached images to show that. But also im trying to use this GET featured to send a variable (HCSR) which comes from an arduino board and sent to raspberry via I2C. I also attached my program. Any advice to that?

Hello i forget to attached an image where i work using V4 to put “15” value. Any response about my question? best regards

Was that confirmation all works as expected from a browser?

If it doesn’t work in a browser you have absolutely no chance with code.

Yes Sr. i use the command as explain and the value update in my tablet and smartphone. I was wondering if i have some chance to make my code work

Hello Blynk, is there any help about this question? @Costas please,if you need more information dont hesitate to send me and email to Best regards

Blynk allow you to use GET to update virtual pins, check the syntax and try that.

I already made it as my upper messages show lines above. I better think to use another kinds of blynk assitance to get a proper answer. Regards

This IS the site to get assistance… and “better” answers are based on better questions, clearly supplied details and most of all, keep trying to work it out on your own as well… don’t just wait for another forum volunteer to drop everything and help.

@Gunner i am totally agree with your answer but do you think my question and my images attached not explain what my specific question is? Could you please read it and give me a feedback? thank you and best regards

I don’t use HTTP API (AKA I dunno :stuck_out_tongue_winking_eye: )… review the answers already given… from your best source @Costas

RIP my issue !!! bye bye to my life,thanks @Costas and @Gunner :hatched_chick::gun:

Sounds like you need more than Blynk assistance :wink:

Before you shoot your chicken… hmmm… phrasing :thinking: Have you really read through all the other topics in this forum on how to properly use HTTP RESTapi?

This is a little snippet I made for reading a DHT:

import Adafruit_DHT
import urllib2

humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4)

humidity = float(round(humidity, 2))
temperature = float(round(temperature, 2))

if humidity is not None and temperature is not None:
  url_humidity = '<token>/update/V1?value=%s' % (format(humidity))
  url_temperature = '<token>/update/V2?value=%s' % (format(temperature))


  print 'Geen data'

I just execute this with crontab every 30s (way overkill, but ok).

@reboot while true ; do python /home/pi/blynk/python/ & sleep 30; done >/dev/null 2>&1
1 Like