sensorserver

package module
Version: v0.0.0-...-b62ec65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2015 License: GPL-2.0 Imports: 15 Imported by: 0

README

Sensorserver

Sensorserver is simple all-in-one solution for store and serve timeseries from sensors. I develop this application for my Raspberry Pi.

Build

./prepare.sh
go get -u github.com/0rph3us/astrotime
go get -u github.com/BurntSushi/toml
go get -u github.com/gin-gonic/gin
go get -u github.com/boltdb/bolt

go run cmd/main.go
build package

You need fpm for building the package.

./build.sh

Dependencies

  • Gin the web framework
  • toml is the format for the configuration file
  • BoltDB the storage backend
  • Astrotime for calculate the sunset and sunrise

API

/boltdb/backup

Support GET and HEAD requests. Get a binary stream of the database file.

curl -J -O http://127.0.0.1:8080/boltdb/backup
/boltdb/stats

Support GET and HEAD requests. The response is a JSON.

curl 127.0.0.1:8080/boltdb/stats?pretty=true
/sensor

Support GET, HEAD and PUT requests. The GET response is JSON Array with the name of all sensors. The PUT method put date from different sensors into to storage backend.

curl -XPUT 'http://127.0.0.1:8080/sensor' -d '[
    {
        "Timestamp": 1445311973,
        "Sensors": {
            "temp_bmp085": 23.5,
            "humidity": 43.7,
            "pressure": 1004.53467
        }
    },
    {
        "Timestamp": 1445312973,
        "Sensors": {
            "temp_bmp085": 23.4,
            "humidity": 43.6,
            "pressure": 1002.8329
        }
    }
]'
/sensor/:name

Support GET, HEAD and PUT requests for a specific sensor. GET returns a JSON array with timestamp-value objects. The timestamp is in seconds since 01.01.1970

curl -XGET 'http://127.0.0.1:8080/sensor/pressure?pretty=true'
[
    {
        "Timestamp": 1413011716487,
        "Value": 1003.35
    },
    {
        "Timestamp": 1413076519461,
        "Value": 1003.17896
    },
    {
        "Timestamp": 1413141322435,
        "Value": 1002.38873
    },
    {
        "Timestamp": 1413206125409,
        "Value": 996.93915
    }
]

The PUT method put new data into the server. The timestamp is a normal 32 Bit Unixtimestamp.

curl -XPUT 'http://127.0.0.1:8080/sensor/humidity' -d '[
    {
        "Timestamp": 1412979315,
        "Value": 57.9
    },
    {
        "Timestamp": 1412979343,
        "Value": 58
    },
    {
        "Timestamp": 1412979394,
        "Value": 58
    },
    {
        "Timestamp": 1412979407,
        "Value": 58.1
    },
    {
        "Timestamp": 1412979417,
        "Value": 57.9
    },
    {
        "Timestamp": 1412979437,
        "Value": 58.1
    },
    {
        "Timestamp": 1412979557,
        "Value": 58.3
    }
]'

Alternative

All alternatives looks good. Graphite has the most functions, but the project looks dead. Grafana is a very good frontend for the 3 backends. This plugin is required for the prometheus datasource.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat32

func BytesToFloat32(b []byte) (f float32)

BytesToFloat32 convert a byte Array to float32

func BytesToInt

func BytesToInt(b []byte) int

BytesToInt convert a byte Array to a int

func Float32Bytes

func Float32Bytes(float float32) []byte

Float32Bytes convert a float32 into a byte Array

func IntBytes

func IntBytes(i int) []byte

IntBytes convert a int into a byte Array

Types

type Config

type Config struct {
	Port        uint16   `toml:"port"`
	Database    string   `toml:"database"`
	Title       string   `toml:"title"`
	Caption     string   `toml:"caption"`
	Latitude    float64  `toml:"latitude"`
	Longitude   float64  `toml:"longitude"`
	MaxPoints   int      `toml:"maxPoints"`
	Sensors     []string `toml:"sensors"`
	SubTitle    string
	Duration    string
	Type        string
	TemplateDir string
}

type MinFloat32Heap

type MinFloat32Heap []float32

func (*MinFloat32Heap) Average

func (h *MinFloat32Heap) Average() float32

func (MinFloat32Heap) Len

func (h MinFloat32Heap) Len() int

func (MinFloat32Heap) Less

func (h MinFloat32Heap) Less(i, j int) bool

func (*MinFloat32Heap) Pop

func (h *MinFloat32Heap) Pop() interface{}

func (*MinFloat32Heap) Push

func (h *MinFloat32Heap) Push(x interface{})

func (MinFloat32Heap) Swap

func (h MinFloat32Heap) Swap(i, j int)

type Sensorserver

type Sensorserver struct {
	// contains filtered or unexported fields
}

func New

func New(filename, datadir, templatedir string) (s *Sensorserver, port uint16, err error)

func (*Sensorserver) Backup

func (s *Sensorserver) Backup(c *gin.Context)

Backup this method returns the hole database file

func (*Sensorserver) GetChart

func (s *Sensorserver) GetChart(c *gin.Context)

func (*Sensorserver) GetSensorData

func (s *Sensorserver) GetSensorData(c *gin.Context)

return data from a sensor in json format This function call reduceData!

func (*Sensorserver) GetSensors

func (s *Sensorserver) GetSensors(c *gin.Context)

func (*Sensorserver) GetSunriseAndSunset

func (s *Sensorserver) GetSunriseAndSunset() string

func (*Sensorserver) Page

func (s *Sensorserver) Page(c *gin.Context)

render the HTML page

func (*Sensorserver) PutMultiSensorData

func (s *Sensorserver) PutMultiSensorData(c *gin.Context)

func (*Sensorserver) PutSensorData

func (s *Sensorserver) PutSensorData(c *gin.Context)

func (*Sensorserver) Stats

func (s *Sensorserver) Stats(c *gin.Context)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL