dvlirclient

package module
v0.0.0-...-d2476db Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: BSD-2-Clause Imports: 10 Imported by: 0

README

dvlir-restapi-go-client

Go Report Card GitHub license GitHub code style GoDoc doc

Description

Golang package - client library for the Device GmbH DvLIR IP network readout adapter REST API. This go client is an open-source library to communicate with the Device GmbH DvLIR IP network readout adapter REST API.

Code Style

This project was written according to the uber-go coding style.

Features

  • Retrieve a csv file with the latest data
  • Retrieve the momentary data
  • Retrieve general information about the device (including information about the connected electric meter, network information, system informatrion)
  • Retrieve and change network information (including if a dhcp server is used, the IP address, subnet mask, gateway and dns-server of the adapter, if a ntp-server is used and the name of the ntp-server)
  • Retrieve and change system information (including the saving interval, the reset safety code, the deletion safety code and if a reset with the default password is allowed)
  • Reset the adapter to factory settings
  • Deleting all saved data
  • Upload a firmware file
  • Restart the adapter

Installation

go get github.com/inexio/dvlir-restapi-go-client

or

git clone https://github.com/inexio/dvlir-restapi-go-client.git

Usage

    //Create a new DvLIR api client
    dvlirClient, err := NewDvLIRClient(ip, pw)
    
    //Login into the adapter to get a valid session id
    err = dvlirClient.Login()
    
    //Retrieve the data file
    file, err := dvlirClient.GetDataFile(10)
    
    //Logout of the adapter again
    err = dvlirClient.Logout()
Tests

Our library provides a few unit and intergration tests. To use these tests, the yaml config file in the config directory must be adapted to your setup.

In order to run a test, run the following command inside of the root directory of this repository:

go test --run <Name of the test you want to run>

If you want to check if your setup works, run:

go test --run TestDvLIRClient_Setup

It must be noted, that you have to run the tests one at a time, because quite a few of the tests cause the adapter to restart, which would cause the other tests to fail.

If you want to upload a firmware file to your adapter, the firmware file needs to be in the project folder.

Getting Help

If there are any problems or something does not work as intended, open an issue on GitHub.

Contribution

Contributions to the project are welcome.

We are looking forward to your bug reports, suggestions and fixes.

If you want to make any contributions make sure your go report does match up with our projects score of A+.

When you contribute make sure your code is conform to the uber-go coding style.

Happy Coding!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataLine

type DataLine struct {
	Index        string `json:"index"`
	Date         string `json:"date"`
	Time         string `json:"time"`
	DvLIRSn      string `json:"dvlir_sn"`
	MeterNumber  string `json:"meter_number"`
	OneEightZero string `json:"one_eight_zero"`
	OneEightOne  string `json:"one_eight_one"`
	OneEightTwo  string `json:"one_eight_two"`
	TwoEightZero string `json:"two_eight_zero"`
	TwoEightOne  string `json:"two_eight_one"`
	TwoEightTwo  string `json:"two_eight_two"`
	Power        string `json:"power"`
	Status       string `json:"status"`
}

DataLine contains the contents of a single line of the daten.csv file

type DataLines

type DataLines []DataLine

DataLines is an array of DataLines.

type DvLIRClient

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

DvLIRClient is an implementation of the client specified for dvlir

func NewDvLIRClient

func NewDvLIRClient(ipAddress string, password string) (*DvLIRClient, error)

NewDvLIRClient generates a new dvlir api-client object which can be used to communicate with the DvLIR-API

func (*DvLIRClient) AllowResetWithPwd

func (d *DvLIRClient) AllowResetWithPwd(allow string) (string, error)

AllowResetWithPwd a performs AllowResetWithPwd operation via the dvlir api-client

func (d *DvLIRClient) Blink(blink int, pause int) (response int, err error)

Blink a performs Blink operation via the dvlir api-client

func (*DvLIRClient) ChangeNetworkSettings

func (d *DvLIRClient) ChangeNetworkSettings(dhcp, ip, sub, gw, dns, ntpName, ntpServer, setDt string) (string, error)

ChangeNetworkSettings a performs ChangeNetworkSettings operation via the dvlir api-client

func (*DvLIRClient) ChangePassword

func (d *DvLIRClient) ChangePassword(pw1, pw2, pw3 string) (string, error)

ChangePassword a performs ChangePassword operation via the dvlir api-client

func (*DvLIRClient) ChangeSavingInterval

func (d *DvLIRClient) ChangeSavingInterval(interval string) (string, error)

ChangeSavingInterval a performs ChangeSavingInterval operation via the dvlir api-client

func (*DvLIRClient) DataLineConversion

func (d *DvLIRClient) DataLineConversion(input string) DataLine

DataLineConversion converts a string into a DataLine struct

func (*DvLIRClient) DeleteData

func (d *DvLIRClient) DeleteData(code string) (string, error)

DeleteData a performs DeleteData operation via the dvlir api-client

func (*DvLIRClient) GetDataFile

func (d *DvLIRClient) GetDataFile(lines int) (DataLines, error)

GetDataFile a performs GetDataFile operation via the dvlir api-client

func (*DvLIRClient) GetGeneralInformation

func (d *DvLIRClient) GetGeneralInformation() (GeneralInfo, error)

GetGeneralInformation a performs GetGeneralInformation operation via the dvlir api-client

func (*DvLIRClient) GetMomentaryValues

func (d *DvLIRClient) GetMomentaryValues() (MomentaryValues, error)

GetMomentaryValues a performs GetMomentaryValue operation via the dvlir api-client

func (*DvLIRClient) GetNetworkInformation

func (d *DvLIRClient) GetNetworkInformation() (NetworkInfo, error)

GetNetworkInformation a performs GetNetworkInformation operation via the dvlir api-client

func (*DvLIRClient) GetSystemInformation

func (d *DvLIRClient) GetSystemInformation() (SystemInfo, error)

GetSystemInformation a performs GetSystemInformation operation via the dvlir api-client

func (*DvLIRClient) HashTagSplitter

func (d *DvLIRClient) HashTagSplitter(input string) []string

HashTagSplitter splits a string at every instance of a #

func (*DvLIRClient) LineSplitter

func (d *DvLIRClient) LineSplitter(input string) []string

LineSplitter splits a string at every instance of \r\n

func (*DvLIRClient) Login

func (d *DvLIRClient) Login() error

Login performs a login via the dvlir api-client

func (*DvLIRClient) Logout

func (d *DvLIRClient) Logout() error

Logout performs a logout via the dvlir api-client

func (*DvLIRClient) NTPServerTest

func (d *DvLIRClient) NTPServerTest(ntpName string) (int, error)

NTPServerTest a performs NTPServerTest operation via the dvlir api-client

func (*DvLIRClient) ResetAll

func (d *DvLIRClient) ResetAll(rCode string) (string, error)

ResetAll a performs ResetAll operation via the dvlir api-client

func (*DvLIRClient) Restart

func (d *DvLIRClient) Restart() (string, error)

Restart a performs Restart operation via the dvlir api-client

func (*DvLIRClient) UploadFirmware

func (d *DvLIRClient) UploadFirmware(filePath string) (string, error)

UploadFirmware a performs UploadFirmware operation via the dvlir api-client

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Status  int    `json:"status"`
}

ErrorResponse - Contains error information.

type GeneralInfo

type GeneralInfo struct {
	ServerIDMeter    string `json:"server_id_meter"`
	MeterNumber      string `json:"meter_number"`
	ManufacturerCode string `json:"manufacturer_code"`
	IPAddress        string `json:"ip_address"`
	Gateway          string `json:"gateway"`
	DNSServer        string `json:"dns_server"`
	NetworkName      string `json:"network_name"`
	MACAddress       string `json:"mac_address"`
	SavingInterval   string `json:"saving_interval"`
	Date             string `json:"date"`
	Time             string `json:"time"`
	DeviceSn         string `json:"device_sn"`
	FirmwareVersion  string `json:"firmware_version"`
}

GeneralInfo contains the response of the api in case of a GetGeneralInformation request

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Body       *ErrorResponse
}

HTTPError - Represents an http error returned by the api.

func (HTTPError) Error

func (h HTTPError) Error() string

type MomentaryValues

type MomentaryValues struct {
	MeterNumber     string    `json:"meter_number"`
	OBISNum         string    `json:"obis_num"`
	MomentaryPower  string    `json:"momentary_power"`
	MeterReadingAP  string    `json:"meter_reading_ap"`
	MeterReadingAM  string    `json:"meter_reading_am"`
	MeterReadingsAP [9]string `json:"meter_readings_ap"`
	MeterReadingsAM [9]string `json:"meter_readings_am"`
	Status          string    `json:"status"`
	SavingInterval  string    `json:"saving_interval"`
}

MomentaryValues contains the response of the api in case of a GetMomentaryValues request

type NetworkInfo

type NetworkInfo struct {
	DHCPServer string `json:"dhcp_server"`
	IPAddress  string `json:"ip_address"`
	SubnetMask string `json:"subnet_mask"`
	Gateway    string `json:"gateway"`
	DNSServer  string `json:"dns_server"`
	NTPServer  string `json:"ntp_server"`
	NTPName    string `json:"ntp_name"`
}

NetworkInfo contains the response of the api in case of a GetNetworkInformation request

type NotValidError

type NotValidError struct{}

NotValidError - Is returned when the client was not initialized properly

func (*NotValidError) Error

func (m *NotValidError) Error() string

type SystemInfo

type SystemInfo struct {
	SavingInterval      string `json:"saving_interval"`
	ResetCode           string `json:"reset_code"`
	DeleteCode          string `json:"delete_code"`
	ResetWithDefaultPwd string `json:"reset_with_default_pwd"`
}

SystemInfo contains the response of the api in case of a GetSystemInformation request

Jump to

Keyboard shortcuts

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