Documentation
¶
Overview ¶
SDS011conn is connection for writing and reading packages from serial line
This is interface. Different implementations are made for linux and tinygo-microcontroller environments
Index ¶
- Constants
- func EnoughBytes(arr []byte) bool
- func GetUptime() int64
- func NormalizePM10(pm10 float64, humidity float64) float64
- func NormalizePM25(pm25 float64, humidity float64) float64
- type Conn
- type LinuxConn
- type Packet
- func NewPacket_DataReply(deviceId uint16, pm2_5 uint16, pm10 uint16) Packet
- func NewPacket_QueryData(deviceId uint16) Packet
- func NewPacket_QueryVersion(deviceId uint16) Packet
- func NewPacket_QueryVersionReply(deviceId uint16, year byte, month byte, day byte) Packet
- func NewPacket_SetId(deviceId uint16, newDeviceId uint16) Packet
- func NewPacket_SetIdReply(deviceId uint16) Packet
- func NewPacket_SetPeriod(deviceId uint16, write bool, period byte) Packet
- func NewPacket_SetPeriodReply(deviceId uint16, write bool, period byte) Packet
- func NewPacket_SetQueryMode(deviceId uint16, write bool, query bool) Packet
- func NewPacket_SetQueryModeReply(deviceId uint16, write bool, query bool) Packet
- func NewPacket_SetWorkMode(deviceId uint16, write bool, work bool) Packet
- func NewPacket_SetWorkModeReply(deviceId uint16, write bool, work bool) Packet
- func (p *Packet) CalcChecksum() byte
- func (p *Packet) ChecksumOk() bool
- func (p *Packet) FromBytes(uptimeNow int64, arr []byte) error
- func (p *Packet) GetIsWrite() bool
- func (p *Packet) GetMeasurement() (Result, error)
- func (p *Packet) GetPeriod() (byte, error)
- func (p *Packet) GetQueryMode() (bool, error)
- func (p *Packet) GetSetId() (uint16, error)
- func (p *Packet) GetVersionString() (string, error)
- func (p *Packet) GetWorkMode() (bool, error)
- func (p *Packet) MatchToId(id uint16) bool
- func (p Packet) String() string
- func (p *Packet) ToBytes() []byte
- func (p *Packet) ToDebugText() string
- type Result
- type Sds011
- func (p *Sds011) ChangeToWork(toWork bool) error
- func (p *Sds011) DoQuery() error
- func (p *Sds011) GetSettings() (Sds011Settings, error)
- func (p *Sds011) IsWorking() (bool, error)
- func (p *Sds011) PowerLine(enabled bool)
- func (p *Sds011) Run() error
- func (p *Sds011) SetSettings(newSettings Sds011Settings) error
- func (p *Sds011) SyncSettingsFromDevice() error
- type Sds011Settings
Constants ¶
View Source
const ( SDS011TOSENSORSIZE = 19 SDS011FROMSENSORSIZE = 10 )
Get optimized serial transmit by exact packet size
View Source
const ( SDS011PACKETSTART = 0xAA SDS011PACKETSTOP = 0xAB )
View Source
const ( COMMANDID_CMD = 0xB4 COMMANDID_RESPONSE = 0xC5 COMMANDID_DATAREPLY = 0xC0 //First byte in data is not function number )
View Source
const ( FUNNUMBER_REPORTINGMODE = 2 //NON- volatile FUNNUMBER_QUERYDATA = 4 FUNNUMBER_SETID = 5 //NON-volatile FUNNUMBER_SLEEPWORK = 6 //Is needed? Trigger? FUNNUMBER_PERIOD = 8 //NON -volatile FUNNUMBER_VERSION = 7 )
View Source
const ( TIMEOUTRESPONSE = 500 //Query is sent, how long wait sensor response SYNCRETRYINTEVAL = 3000 //How long to wait before syncing settings from sensor )
View Source
const ANYDEVICE = 0xFFFF
Variables ¶
This section is empty.
Functions ¶
func EnoughBytes ¶
func NormalizePM10 ¶
func NormalizePM25 ¶
Stolen from https://github.com/piotrkpaul/esp8266-sds011
Types ¶
type LinuxConn ¶
type LinuxConn struct {
// contains filtered or unexported fields
}
func CreateLinuxSerial ¶
Uses fixed settings for SDS0101
type Packet ¶
type Packet struct { CommandID byte DeviceID uint16 Checksum byte Data []byte Uptime int64 //Extra information to carry around.. timestamping Valid bool //Is ok or not }
func NewPacket_DataReply ¶
func NewPacket_QueryData ¶
func NewPacket_SetId ¶
Set device id. DO NOT USE. Unless really wanted
func NewPacket_SetIdReply ¶
func NewPacket_SetPeriod ¶
Set working period
func NewPacket_SetQueryMode ¶
func NewPacket_SetWorkMode ¶
4)Set device sleep work time
func (*Packet) CalcChecksum ¶
func (*Packet) ChecksumOk ¶
func (*Packet) FromBytes ¶
Require packet starting with 0xAA and end 0xAB Remember to add uptime here. (exact timestamp)
func (*Packet) GetIsWrite ¶
func (*Packet) GetMeasurement ¶
func (*Packet) GetQueryMode ¶
func (*Packet) GetVersionString ¶
func (*Packet) GetWorkMode ¶
Assuming valid packet (it have data, only valid function)
func (*Packet) ToDebugText ¶
type Sds011 ¶
type Sds011 struct { PassiveMode bool //Only listen Id uint16 //Listen only these messages ErrorsCh chan error //Push nil if recovered or came online DetectedSensor chan uint16 //In case of multiple sensors. add item here when found valid package with new ID // contains filtered or unexported fields }
func InitSds011 ¶
func (*Sds011) ChangeToWork ¶
func (*Sds011) GetSettings ¶
func (p *Sds011) GetSettings() (Sds011Settings, error)
func (*Sds011) SetSettings ¶
func (p *Sds011) SetSettings(newSettings Sds011Settings) error
Check situation first from sensor. Do not update if not needed, avoid re-flashing eeprom
func (*Sds011) SyncSettingsFromDevice ¶
type Sds011Settings ¶
type Sds011Settings struct { QueryMode bool Period byte //0=30sec no sleep, 1=1 minute period Version string //can be queried if active mode READONLY }
func (*Sds011Settings) PeriodDuration ¶
func (p *Sds011Settings) PeriodDuration() time.Duration
Click to show internal directories.
Click to hide internal directories.