Code Monkey home page Code Monkey logo

spaceapi-server's Introduction

SpaceAPI-Server

SpaceAPI Server written in Go

This server can return a valid SpaceAPI-string in version 13 as specified here and provides further API endpoints for modification of the returned values.

Features

Implemented

  • Return of valid SpaceAPI strings
  • Modification of SpaceAPI
    • state
    • sensors
      • temperature
      • humidity
  • Persistence using a database (sqlite tested)
  • Simple token authentication of modification-requests
  • Static override of some values (for example to set space details like name, location, url etc.)
  • Dockerfile

Planned

  • Support for the whole SpaceAPI (with all specified fields) including modification
  • Support for HTTPS (use with reverse proxies for now)

Running

  • Create a config and an override file in /srv/spaceapi-server like in this example (with your values)

config.json

{
    "db":"sqlite3",
    "dbconnection":"data/lite.db",
    "port":8080,
    "debug":false
}

override.json

{
    "API":   "0.13",
    "Space": "vspace.one",
    "Logo":  "https://vspace.one/pic/logo_vspaceone.svg",
    "URL":   "https://vspace.one",
    "location": {
        "Address": "Wilhelm-Binder-Str. 19, 78048 VS-Villingen, Germany",
        "Lat":     48.065003,
        "Lon":     8.456495
    },
    "contact": {
        "Phone":   "+49 221 596196638",
        "Email":   "[email protected]",
        "Twitter": "@vspace.one"
    },
    "IssueReportChannels": [
        "email",
        "twitter"
    ]
}
  • docker run --name spaceapi-server -v /srv/spaceapi-server/:/go/src/github.com/vspaceone/SpaceAPI-Server/data vspaceone/spaceapi-server
  • Token and database files should be created automagically

API

Getting SpaceAPI string

GET on /spaceapi
GET on /spaceapi.json

Returns the whole SpaceAPI string

Setting SpaceAPI values

POST on /spaceapi

Makes it possible to send data similar to the SpaceAPI string to set specific values (for now only setting of state.open, sensors.temperature and sensors.humidity is possible).

Note that setting these values is only possible if the right token is specified in Header as X-Auth-Token. The token you need to specify is generated at first start of this application. When specifying a wrong token or none the server will respond with status 401.

Examples for POST payload:

Setting state.open

{
    "state": {
        "open": false,
        "lastchange": 1519502622
    }
}

Setting sensors.temperature and sensors.humidity

{
    "sensors": {
        "temperature": [
            {
                "value": 25,
                "unit": "°C",
                "location": "Maschinenraum"
            },
            {
                "value": 22,
                "unit": "°C",
                "location": "Brücke"
            }
        ],
        "humidity": [
            {
                "value": 50,
                "unit": "%",
                "location": "Brücke"
            },
            {
                "value": 40,
                "unit": "%",
                "location": "Maschinenraum"
            }
        ]
    }
}

Getting past sensor data

Not possible anymore. This server only saves the current state in its database and presents it as a SpaceAPI. Other tools can be used for monitoring, logging and analyzing changes to the API.

spaceapi-server's People

Contributors

djesionek avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

chaosdorf

spaceapi-server's Issues

Spaceapi is no longer working if history is to dataintense.

Wenn zu viele Daten in der Datenbank stehen, funktioniert die Spaceapi nicht mehr.

Mögliche Lösungen:

  • keine History aufzeichnen
  • aktuellen Wert seperat handeln, im RAM beispielsweise
  • Ich hab den Code nicht angesehen. Aber evtl kann man ja das Abfragen an der DB auch per LIMIT 1 machen anstatt SORT. Das sollte eigentlich kein Performanzproblem geben, bei den paar Daten.

Hintergründe:
Die Temperatur und Luftfeuchtesensoren liefern alle 15 Minuten einen neuen Wert. Das würde ich auch ungern weiter runterschrauben. Meine persönliche Datenbank zieht alle 10 Minuten den Spaceapi Status von allen Space in eine InfluxDB. Wir müssen die Historie also an dieser Stelle also garnicht aufzeichnen. Zumal es dann ja nicht mehr funktioniert. Die Perioden der Sensoren zu erhöhen würde das Problem also nur aufschieben.

Spaceapi invalid again

Our spaceapi is invalid again:

{"valid":false,"message":"(root).sensors.temperature: Invalid type. Expected: array, given: null\n(root).sensors.humidity: Invalid type. Expected: array, given: null\n"}

{"valid":false,"message":"(root).sensors.temperature: Invalid type. Expected: array, given: null\n(root).sensors.humidity: Invalid type. Expected: array, given: null\n"}

Looks like similar problem as last time. Try here

Regards,
Max

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.