Hi. I am using the https API to send/get data from Blynk and receiving the “invalid token” error. I have tested the below URL with Chrome and it works OK, with values updated in web dashboard. So I assume the token is, in fact, valid. Is there something else that might be causing this error? Here is my code:
Hello @drewc228. I checked this HTTP API, everything works correctly. Please read https://docs.blynk.io/en/blynk.cloud/device-https-api/update-multiple-datastreams-api#batch-update
Check your device token again.
Format and send an HTTPS API URL from an Arduino program to Blynk, via a web proxy that transmits it as a “get” to the “ny3” Blynk server. I am using the Blues Wireless NoteCard to connect to the Cloud, and using their web hook (“Route”) and proxy server to pass the data to Blynk. I have examined the output from the NoteCard Route and it looks clean.
I have successfully tested the URL with Chrome and Safari, but is it failing when sent through the proxy with an HTML 400 error, sometimes with “Invalid Token”. Any thoughts?
Thanks Pete. An update from this morning’s testing: The HTTPS API appears to be working fine, with “200” results from all of my tests. The error I was getting seems to be from the “other side”, that is, the Blues web hook “WebGet” function which seemed to be inserting “noise” (unknown characters?) into the payload. This resulted in the many “invalid token” messages I was getting. By playing around with the URL in the Blues web hook I was able to eliminate the noise and get successful passage of the code from Blues to Blynk. For reference, here is the Blues code that works:
Hi, sorry for the confusion! I am in the process of moving one of my Blynk applications from online-connected mode to HTTPS API mode, using the Blues cellular Notecard. I have converted all of the virtual write calls to their corresponding API endpoint, but now I have several Blynk WRITE functions to handle. These control the device from the app, doing things like starting/ending a recording session and naming it (think tracking), entering WiFi credentials, turning on/off various filters and corrections, toggling mobile or cloud mode, etc. Question is how best to do these things, in the Blynk user app, without being online with Blynk. Thanks!
If you’re referring to BLYNK_WRITE() then there is no equivalent in HTTP API calls.
The nearest you can get is to constantly poll the Blynk server to see if virtual datastream values have changed, which is messy.
That’s the advantage of using the Blynk C++ library with an always on connection, as processing Blynk.run() in the void loop constantly checks for datastream value changes and calls the appropriate BLYNK_WRITE() callback.
Thanks Pete. Yes, I’d prefer the always-on connection as my WiFi-connected app works well that way. But my clients are looking for a cellular solution and I am trying to find a way forward down that path. As a wireless device, though, power is always an issue, as is connectivity. I currently use a companion phone’s WiFi hotspot to provide that connection to the Internet.
So, I’d like to figure out a way to initialize a Blynk connection with the Blues Notecard. It is at heart a Quectel EG91 LTE /GSM modem, similar to and compatible with the Quectel BG96 that others have used with Blynk (with TinyGSM) Using Blues Notecard is dead simple because they have built an easy-to-use layer above the arduous AT-commands – all the part setting and registration stuff is done with one call. So the trick would be to somehow grab the connection once the modem is registered and show it to Blynk, so that a Blynk session can be established. I did briefly try TinyGSM but couldn’t seem to init the modem.
Appreciate any insights from the Blynk community. Thanks!
You didn’t clarify whether you were referring to BLYNK_WRITE() and now you’ve thrown-in the issue of “power” to the discussion without really elaborating on what that refers to, and what your power requirements are.
Depending on what your actual real-world application is going to be doing, there are possible solutions that you could explore. where the hardware that you’re currently focusing on is the best approach is difficult to say, as you don’t seem to want to share info about your client’s requirements.
I’ll take a step back from the discussion until you feel like sharing more high-level info.
Ok thanks for the feedback Pete.
The 10,000 foot (meters) view of my application is this: my device is a LiPO-powered air quality monitor that contains sensors which sample data every second or so. The device software (Arduino, ESP32) does some some local display, data cleanup, and averaging, then sends the cleaned sensor data up to the Internet every minute via WiFi. I currently utilize a smartphone WiFi hotspot to relay the data from the device to a cellular network, where it’s stored in a ThingSpeak database. Blynk is used primarily for the smartphone App and UX to control the device and manage various operating parameters such as starting/stopping GPS tracking, different modes, etc. I also use the Blynk management console and OTA features to keep track of the 40-some devices I manage.
My users - who include middle and high schools students - would like to eliminate the need for the smartphone hotspot, and would prefer to rely on a cellular modem in the device. I have successfully prototyped a new version based on the Blues Wireless Notecard, utilizing the Blynk HTTPS API. Most of the smartphone app features I had with WiFi are working with the API, except for the above-mentioned BLYNK_WRITE() functions (app to device) which are needed during device setup and operation. Here’s an example of one:
// This function is called whenever Session is started/stopped
BLYNK_WRITE(V90) {
if (param.asInt()) {
blinkLedWidget(); // blink LED
session += ; // iterate session #
Serial.println("Session " + session + "Started at " + timeHack);
if (amTracking) { // if already tracking...
amTracking = false;
}
} else {
Serial.println("Session " + session + "Stopped at " + timeHack);
led2.off(); // set LED to OFF
if (!amTracking) { // if not tracking...
amTracking = true;
}
}
}
I had thought of using some sort of local scrolling display + pushbutton on the device itself, but this seems old-school with the ability to use a much nicer smartphone as the GUI. I was also going to mention BLE but…
So, that’s where I am, trying to engineer a solution for local device control. Thanks as always.