This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

sending data to a web server
#1
Hello,

I am playing with the network connection and trying to send data to a web page using a custom phyphox experiment. If I understand correctly the wiki (https://phyphox.org/wiki/index.php/Network_Connections), there are only two ways to trigger such a connection:
- using the "interval" property of the <connection> block
- using the "trigger" property of a view button

I would like to send a data only once, after a given amount of time, and I would like to avoid using a button. The way I do it now is that I set the interval property at the proper time:

<connection interval="4.6" address="ADDRESS" id="submit" service="http/post" conversion="json" privacy="https://phyphox.org/disclaimer/" autoConnect="true">
      <send id="frequency" type="buffer" init="0">frequency</send>
 </connection>


The experiment is programmed to stopped after 5 seconds (via the "timedRun" and timedRunStopDelay" properties of the analysis block), so the experiment uses the connection twice : one at 0s, one at ~ 4.6 s. The first connection is unwanted, and I plan to disregard it on web side (either via php or python script), but is there a better way of programming the phyphox experiment? Ideally I would like to be able to trigger a connection at a given time, using the <timer> analysis module.


Also, on a side note, each time my phyphox experiment sends a data to my server, the data are received, but a message "Could not parse JSON" appears on my smartphone. I haven't investigate this yet (in fact it helps me by clearly tagging each connection), so it may be a simple problem with my server. I plan to look at it, but if this is a well known problem, I wouldn't mind any pointers.

Thank you in advance,

Cheers,

Fred
Reply
#2
No, there is no better solution at the moment. I would suggest to use the analysis blocks to add metadata to your data submission so you can easily recognize the submission that should be discarded (you could for example submit the result from the timer-block).

The could not parse JSON probably occurs because phyphox tries to parse the result to be written back to the buffers. You can either set the conversion attribute to conversion="none" to discard any response or let your server give a meaningful response that you can show to the user. For example you can respond with {"result": 1}, write it to a phyphox buffer and map different codes to different messages like "submission received" in a view element using its "map" node.
Reply
#3
Hello,

thank you for your reply, it is quite clear I think. I guess I will send a buffer "discard", which I will put to 0 or 1 depending on the value needs to be kept or not.

OK for the JSON parsing, I haven't looked at what to send back to the smartphone yet, your answer gives me ideas.

Cheers,

fred
Reply


Forum Jump: