Save kWh, wattage & power factor using websockets and GoCQL
https://golang.org/doc/install
https://github.com/golang/go/wiki/SettingGOPATH
go get github.com/gocql/gocql
go get github.com/stretchr/testify
When using old golang version
go get github.com/stretchr/testify
If you change the directory name, also change the imports in the go files of this project.
http://cassandra.apache.org/download/
In your cassandra folder run file 'bin/cassandra.exe'
In your cassandra folder run file 'bin/cqlsh.exe'
run setup.sh
Edit conf.json to your setup
go run main.go
go build main.go
`main.exe` is created and can be executed
In general, each message consists of a standard message header followed by request-specific data. The standard message header is structured as follows:
Type | Name | Description |
---|---|---|
uint32 | messageLength | The total size of the message in bytes. This total includes the 4 bytes that holds the message length |
uint32 | requestID | A client or database-generated identifier that uniquely identifies this message. |
uint32 | responseTo | Clients can use the requestID and the responseTo fields to associate query responses with the originating query. |
uint32 | opCode | Type of message. See Request Opcodes for details. |
Opcode Name | Value | Comment |
---|---|---|
OP_REPLY | 1 | Reply to a client request. responseTo is set. |
OP_QUERY | 200 | Query measurements by stone_id(s), fields, time & interval |
OP_INSERT | 100 | Insert measurements by stone_id, time & type + value |
OP_DELETE | 500 | Delete measurements by stone_id, time & types |
type | Name | Description |
---|---|---|
16 byte | header | Message header, as described in Standard Message Header. |
uint32 | flag | (Bit vector to specify flags for the operation. The bit values correspond to the following: 1 Energy Usage - Request - Response 2 Power Usage - Request - Response |
json | payload | Depends on flag |
{
"stoneIDs":[
"5b8d0018acc9bc3124af2cc2"
],
"startTime":"1548252675000", //Epoch in ms
"endTime":"1548252905000", //Epoch in ms
}
{
"startTime":"1548252675000", //Epoch in ms
"endTime":"1548252905000", //Epoch in ms
"stones":[
{
"stoneID":"bf82e78d-24a2-470d-abb8-9e0a2720619f",
"Data":[
{
"time":"1548252673000", //Epoch in ms
"value":
{
"kWh" : 3.0233014
}
},
{
"time":"1548252678000", //Epoch in ms
"value":
{
"kWh" : 2.188571
}
}
]
}
]
}
{
"startTime":"1548252675000", //Epoch in ms
"endTime":"1548252905000", //Epoch in ms
"stones":[
{
"stoneID":"bf82e78d-24a2-470d-abb8-9e0a2720619f",
"Data":[
{
"time":"1548252675000", //Epoch in ms
"value": {"w": 3, "pf" : 1}
},
{
"time":"1548252678000", //Epoch in ms
"value": {"w": 2, "pf" : 1}
}
]
}
]
}
type | Name | Description |
---|---|---|
16 byte | header | Message header, as described in Standard Message Header. |
uint32 | flag | (Bit vector to specify flags for the operation. The bit values correspond to the following: 1 Energy History 2 Power History |
json | payload | Depends on flag |
{
"stoneID":"bf82e78d-24a2-470d-abb8-9e0a2720619f",
"data":[
{
"time":"1548252675000", //Epoch in ms
"kWh":3.3228004
},
{
"time":"1548252679000", //Epoch in ms
"kWh":3.4341154
}
]
}
{
"stoneID":"bf82e78d-24a2-470d-abb8-9e0a2720619f",
"data":[
{
"time":"1548252675000", //Epoch in ms
"watt":3.0233014,
"pf":4.702545
},
{
"time":"1548252679000", //Epoch in ms
"kWh":3.4341154
}
]
}
The database will respond to an OP_QUERY message with an OP_REPLY message.
type | Name | Description |
---|---|---|
16 byte | header | Message header, as described in Standard Message Header. |
uint32 | flag | (Bit vector to specify flags for the operation. The bit values correspond to the following: 1 Energy History - Request 2 Power History - Request |
json | payload | Depends on flag
{
"stoneID":"bf82e78d-24a2-470d-abb8-9e0a2720619f",
"startTime":"1548252679000", //Epoch in ms
"endTime":"1548252680000" //Epoch in ms
}
The database will respond to an OP_QUERY message with an OP_REPLY message.
type | Name | Description |
---|---|---|
16 byte | header | Message header, as described in Standard Message Header. |
uint32 | flag | (Bit vector to specify flags for the operation. The bit values correspond to the following: 1 Ok (Payload depends of Client request message) 2 No Content (No payload) 100 Error |
json | payload | Depends on flag |
{
"code":100,
"message":"StoneID is missing"
}
see errors in datatypes/error.go
go test ./...