PHP scripts for the JSON generation and the status display page
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

SpaceAPI Endpoint And Status Script

The provided scripts are for generating the JSON but also for displaying the space status.

Given the following apache configuration,

<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot "/srv/http/spaceapi"
    <Directory />
        AllowOverride ALL

the scripts are in /srv/http/spaceapi while the following URLs are now available:

If you deploy the endpoint scripts by cloning the repo, you should forbid public access to the .git directory. If you're using Apache as the web server with the module rewrite enabled, you don't need to do anything, .htaccess is already protecting it.


There's not much to say. Simply adapt spaceapi.json to your needs and add here your URL


Status display page

Your space status is displayed on or on respectively.

The status can be displayed either by a button or by a monster.

Display page with a button Display page with a monster

To select one of both edit the following section in template.html

  // uncomment one of both in order to use either the
  // monster or a simple button to display the status

How to update sensor data?

To push data to the endpoint scripts the data structure to be sent to the server is a subset of the specification version 13.

E.g. to push the door status and two temperature sensor values your measurement unit (Raspberry Pi, Arduino, ...) must use the following structure.

    "state": {
        "open": true
    "sensors": {
        "temperature": [
            { "value": 31 },
            { "value": 23 }

Note: if you need to update an array of sensors this must be done in the same request since the order matters. This means that at the moment it's impossible to update the first temperature sensor by one microcontroller and the second by another. However different sensor arrays can be updated independently so in this case the state/open and sensors/temperature sensors could be updated in a separate request. An array is anything between the brackets [] so if you also had sensors/barometer you could update this in a separate request as well.

After urlencoding the json you make a GET request to the URL schema as shown below.<api_key>&sensors=<urlencoded_json>

These parameters must be provided:

  • key, this value is a random string to protect the update script. This is not a strong protection and it's highly recommended to call the script via SSL. To change the key, simply edit config.json.
  • sensors, the sensor data to be updated server-side. You can push one single value or a whole bunch of sensor instances at once.

Example URL for updating the hackerspace/door status:{%22state%22:{%22open%22:false}}

The following PHP code shows how to push data to your endpoint.

// change this to your actual endpoint URL without a trailing slash 
$endpoint_url = "";

// if you changed the default api key in the endpoint script(s)
// you must change this key here too, otherwise no sensor data
// are updated server-side
$key = "86f7896f97asdf89u0a9s7d7fdasgsda88af";

$sensors = <<<JSON
    "state": {
        "open": true
    "sensors": {
        "temperature": [
            { "value": 31 },
            { "value": 23 }

// minify the json
$sensors = json_encode(json_decode($sensors));
$sensors = urlencode($sensors);

$ch = curl_init("$endpoint_url/sensor/set/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "sensors=$sensors&key=$key");
$data = curl_exec($ch);

If the URL, where you're trying to push, is a redirect, the snippet might not work under certain conditions. Read this to find out why.


curl --data-urlencode sensors='{"state":{"open":false}}' --data key=86f7896f97asdf89u0a9s7d7fdasgsda88af

How to integrate the status with WordPress?

  • Login to your WordPress Backend
  • Click on Appearance > Widgets in the left sidebar
  • Drag the Text widget to your primary sidebar or wherever you want it
  • Now put this code line to your widget input field: <iframe src="">