gop1
1.0.0
这是一个Golang库,可读取主要在荷兰使用的所谓的智能能计的P1数据。 P1是荷兰电力电网公司的协议,并在NetBeheernederland.nl上进行了描述。比利时部署的智能电表实施了相同的协议,但是电网公司定义了一些其他数据类型。这些类型在E-MUCS H规范中定义。
要读取P1数据,您将需要像P1到USB电缆之类的东西。 P1端口本质上是一个串行端口,其中每秒都会倾倒数据(所谓的P1电报)。
package main
import (
"fmt"
"github.com/skoef/gop1"
)
func main () {
// open a new reader to given USB serial device
p1 , err := gop1 . New (gop1. P1Config {
USBDevice : "/dev/ttyUSB0" ,
})
if err != nil {
panic ( err )
}
// start reading data
// this will send new telegrams to the channel p1.Incoming
p1 . Start ()
for telegram := range p1 . Incoming {
// loop over the objects in the telegram to find types we're interested in
for _ , obj := range telegram . Objects {
switch obj . Type {
case gop1 . OBISTypeInstantaneousPowerDeliveredL1 :
fmt . Printf ( "actual power usage: %s %s n " , obj . Values [ 0 ]. Value , obj . Values [ 0 ]. Unit )
}
}
}
}在示例/文件夹中,是一个示例应用程序,该应用程序收集相关指标,并通过Prometheus兼容的HTTP端点提供刮擦。
Marcel de Graaf的SmartMeter项目启发了我写这样的东西。我喜欢他的作品,但正在寻找一个更可笨拙的图书馆,而不是实际的应用程序。另外,还有很多Python项目以及P1支持提供了一些见识。