Interactivity between HTML-file and Photon through Particle.functions and Particle.variables

I have a Photon application with some Particle variables and some Particle functions and I can perfectly interact with the Photon by using Particle console.
I intend however to use the system for monitoring some analog topics that I send once per hour to an HTML page.
As I do not want to use WiFi/Cloud connection permanently, the connection is activated and disactivated for about half a minute per hour by the application running on the Photon.
If I nevertheless occasionally want to connection to remain active, I have one Particle.function to prevent that the Photon application disconnects and another Particle.function that is used for switching the connection off manually.
Now this all works fine when applying both Particle.functions from the Particle console on my PC or from the iOS version of the console.

Now I want to do exactly the same thing from an HTML-file.
I defined some HTML-functions to read the distinct Particle variables using “.get(urlA, {access_token: accessToken}, callbackSTAT……."-statements. I activate these functions every 15 seconds from the HTML page (rather similar to what bko once documented in the tutorial: Reading Spark Variables with Your Own HTML File). That also works fine from the HTML page. Then I added the two HTML functions to control the Particle.functions that I've described above.. They are really very basic; not much more than: ".post(urlB, {params: message, access_token: accessToken……”-statements.
That does not work properly. You would expect that there is enough time in between the polling of the Particle variables as described above to allow for the Particle.functions to be handled. but in fact the timing of the mechanism is highly irregular: if you activate a Particle function from the HTML page, the Photon might respond immediately, or might react after “minutes”, or not at all.
Are there any precautions that I should take into account when sending Particle variables from within a HTML -file?

Not sure what that means?
You cannot send a Particle variable. Variables are registered by the device for collecting and you can request the current value of that variable remotely.

Sorry, the wording was rather inaccurate.
I am sending data (a message “1” or “0”) to the Particle.functions (so: not a variable!) from the HTML page using $.post(url…etc. and not more than that.
The Photon responds sometimes immediately, sometimes after minutes and sometimes not at all, while activating these very same Photon.functions from Particle console works fine.
Could it be that the way that the Photon handles “post” and “get”-requests may interfere somehow?
Is there some mechanism that I am unaware of, or are there any timing constraints or otherwise, that you should take into account in order to have the HTML page act similar to the Particle console?
Is there perhaps a way to prioritize Particle functions in such a way that they are given priority above all get-requests?

The console also just sends POST requests and doesn’t use any special magic to trigger functions.
Have you tried CLI to check how the latency is that way?
Is your device permanently on when you check latency?

@ScruffR
Coming back to the issue of a few weeks ago: the thing I mentioned then is solved: it was a fault in my code that caused the very slow response…

However: I see something else that relates to the topic that I raised: I am interacting with my Photon using both the particle console AND (often at the same time) an own webpage that I wrote myself (with a number of GET’s and POST’s).
This resulted into frequent disturbances of the communication (Status LED solid Cyan, or starting to blink after a long period of breathing, system not responding).
I’ve now changed the webpage in such a way that the POST’s are only executed when de device actually shows that it is connected to the cloud (through a Particle.variable).
It looks like this works fine now,but I still have to test it for a longer period.

I do not know enough about how these POST’s are handled, but it looks like when the webpage attempts to send POST’s to the device while the latter is not connected yet, the attempts of the device to communicate with Particle Cloud, once it is activated from the loop, results in the disturbances I have observed.
Do you know if that would be a valid reasoning?
Or am I just Lucky that the system works now (in which case I do not feel comfortable on the long term stability of my system…)
I’d appreciate your comment!

This would suggest some kind of deadlock between system and application - e.g. when accessing shared resources like HW interfaces.

that also suggests a blocking portion of code but less severe than a deadlock.

To advise on possible solutions we'd need to see your firmware and also the web app.

1 Like

@ScruffR
What is the best way to send these files to you?
(I tried to add them, but it exceeded the max amount of data (56000 vs 32000)

Which IDE are you using?
You could use some cloud storage like One Drive, Google Drive, Dropbox or even GitHub.