Broadcast sensor data to the web from OF

Hi there,

Looking for a way to make sensor data available online from OF. I have something working now with ofxFTP uploading a .dat file on my website everyday but I’d like to have something live, updating sensor data every 5 seconds or so. The data stream would be going on for several months on a computer at home and I’d access the stream in different locations with my laptop once or twice a month for a show.

Can someone point me in a good direction/addon?


Hi! A simple approach would be to send your data in a http request, like this:

ofHttpResponse resp = ofLoadURL("");
cout << << endl;

There you would be sending two GET values to a PHP script. You would have to write a PHP script that receives value1 and value2 and stores them in a text file or to a database. Security can be an issue (if someone starts calling your script sending random data), so you should validate the input and ideally use https instead of http.
The data stored in the server could be later accessed using a web browser, or from another OF application.

In some cases you can also write server side programs in other languages like JavaScript (with nodejs) or Python, but that’s much less common than PHP, which is available in almost every server.

You could also search online for “iot online database api” to find a free database that don’t require any server side programming, but I haven’t tried any of those. Maybe someone can recommend one?

Thanks for the quick reply! Looks clear to me I will give it a go and repost results in a couple of weeks.

i would like to get data from the web and use it in openframeworks, commands like start or stop, or just numbers.
my big plan is to connect a particle photon to openframeworks, i will let the photon send data to a webhook and i want to retrieve that data with openframeworks and use it there.
is this possible?

@noobCoder it is possible. You either query the web server regularly from OF to find out if there’s new data, or you keep a open connection to the server with something like web sockets, which allows the server to send messages to OF. OSC can also work, for instance if you have a local Raspberry PI on the same network which receives your photon data and sends it to OF.

The exact implementation will depend on many things: OSes, which approach you use, which kind of API the server has (if any), etc.

thank for the response.
do i need any addons for this? do you know any examples or tutorials were i can start to learn this?


Just to let you guys know where I am on this, I did the php script thing and it worked very good. Then 5 days later my site got hacked… I still have to figure out that httpS thing…

Here are the php scripts:

First file is get_data.php

Query string <?php $File = "data.txt"; $Handle = fopen($File, 'r'); echo fgets($Handle); close($Handle); ?>

then set_data.php

Query string <?php $File = "data.txt"; $Handle = fopen($File, 'w'); $Data = $_GET["data"]; fwrite($Handle, $Data); fclose($Handle); ?>

And here is the oF thing

//to send data
string data_send = “”;
time_now = ofToString(ofGetDay()) + ofToString(ofGetHours()) + ofToString(ofGetMinutes()) + ofToString(ofGetSeconds());
ofHttpResponse resp = ofLoadURL(data_send + time_now);

//to get data
ofHttpResponse resp = ofLoadURL(“”);
cout <<;

Sad to hear your site got hacked! How did you notice?

What you should do with $_GET[“data”] is to remove everything that should not be there. This can get you started:

If you only expect numbers and commas then remove everything else with a regular expression. Some examples:

@noobCoder I don’t know of any tutorials. It would be a good topic: capture data with sensors, send it to a web server, access it from OF.