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

Update Time-Input via Rest-API not working

Hi,
i try to use a “time input” widget on android to set time on for example V7 and also i want to set this time on V7 via rest-api.

at first i set the time via android app. then read out via rest api and get, for example:

# curl -k --output - 'https://server/token/get/V7'
["58826Europe/Berlin7200"]

when i update via

curl -k --include --request PUT --header "Content-Type: application/json" --data-binary "[\"42380Europe\/Berlin7200\"]" 'https://server/token/update/V7'

i can get the new value by:

# curl -k --output - 'https://server/token/get/V7'
["42380Europe/Berlin7200"]

But there is no update in android app. the old value is still shown.
When i open the widget to set a new time… BUT close it via left arrow in the corner WITHOUT EDITING it. the old value is set again… which i proof via

# curl -k --output - 'https://server/token/get/V7'
["58826Europe/Berlin7200"]

so… it seems, there is a bug?

p.s. what kind is this timeformat? i’ve got unixtimestamp and need it to update V7

It’s the time in seconds from midnight. Rxplained in the information for the widget:

Time Input

Time input widget allows you to select start/stop time, day of week, timezone, sunrise/sunset formatted values
and send them to your hardware. Supported formats for time now are HH:MM and HH:MM AM/PM .

Hardware will get selected on UI time as seconds of day ( 3600 * hours + 60 * minutes ) for start/stop time.
Time that widget sends to hardware is user local time.
Selected days indexes :

Monday - 1
Tuesday - 2
...
Saturday - 6
Sundays - 7

You can also change state of widget on UI. See below sketches.

Sketch: Simple Time Input for start time

Sketch: Advanced Time Input

Sketch: Update Time Input State on UI

The last of those links to sketches includes this:

Blynk.virtualWrite(V1, startAt, stopAt, tz);

  //you may also pass day
  //char days[] = "1"; //Monday
  //Blynk.virtualWrite(V1, startAt, stopAt, tz, days);

  //or days
  //char days[] = "1,2,3"; //Monday, Tuesday, Wednesday
  //Blynk.virtualWrite(V1, startAt, stopAt, tz, days);

which makes me think that you’d need to be sending an array as part of your API call.

Pete.

  1. Add your android app’s version, your Android device model and OS version
  2. The value for Time Input has several options concatenated via ‘\0’ separator - are you sure you are sending a correct format value?

Hey… thx for your reply…
i think the seperator is the problem… i stored the value that curl gets in a textfile now… and now i see special characters that seem to make the problems.
i did not use any special character in my prevous tries.

so i need to know how to send the separator via curl…

my android is lineageOS 14.1 aka android 7.1.2
device is bq - aquaris x5 plus
blynk app V 2.27.5

i tried

printf "[\"61691\x00\x00Europe/Berlin\x00\x007200\"]" | curl -k --output - --include --request PUT --header "Content-Type: application/json" --data-binary @- 'https://server/token/update/V7'

but the result is: Error parsing body param.

so… Null-Byte as separator seems to be not the only problem. I/we need the correct api syntax on this

You should send 5 parameters separated by ‘\0’:

  1. startAt - number of second of the day or “” (never), “sr” (sunrise), “ss” (sunset)
  2. stopAt - same as previous
  3. valid timezone id
  4. days separated by coma or empty string for all days (indexes as in the docs for this widget)
  5. timezone offset in seconds

Please try also write value via get method
https://blynkapi.docs.apiary.io/#reference/0/write-pin-value-via-get/write-pin-value-via-get

Maybe @Dmitriy can help with this later

i wasn’t able to get it working via PUT-method… but it works via GET Method and %00 as separator

so, this example for 00:00:55 in my Timezone works:

curl -k --include 'https://server/token/update/V7?value=55%00%00Europe/Berlin%00%007200'

i would prefer a PUT method… but this works… now i have to convert unixtimestamp to the blynk time-format. maybe there is already such a code to convert? (i would prefer bash-script)

thx a lot…
maybe @Dmitriy (or someone else) is able to figure out syntax for PUT-method - this would be nice

Hello. For multiple params, you have to use token/update/V7?value=55&value=11&value=66 etc

thx a lot…
i don’t know why i did not try yesterday the typical syntax for multiple values… but well… now i did… and PUT also works… like this:

curl --include \
     --request PUT \
     --header "Content-Type: application/json" \
     --data-binary "[
    \"1\",
    \"2\",
    \"3\",
    \"4\",
    \"5\"
]" \
'https://server/token/update/V7'

what i did not before: using placeholder for every parameter. it’s ok if a value is empty, but it must be send as empty. And to reset other values, there must be send minimum one value. (for example timezone)

so, i think, this topic is solved… sorry for any inconveniences =)