-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add dragino sensor #25
Conversation
func (conf *Config) getNodeConfig(decoderFilePath string) node.Config { | ||
return node.Config{ | ||
JoinType: conf.JoinType, | ||
DecoderPath: decoderFilePath, | ||
Interval: conf.Interval, | ||
DevEUI: conf.DevEUI, | ||
AppKey: conf.AppKey, | ||
AppSKey: conf.AppSKey, | ||
NwkSKey: conf.NwkSKey, | ||
DevAddr: conf.DevAddr, | ||
Gateways: conf.Gateways, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we have other sensors create their own node.Config
, then we can reuse all of the validation used in the node implementation
resource.Named | ||
logger logging.Logger | ||
|
||
node node.Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the dragino LHT65N wraps a node implementation, so we can easily reuse all of the node functionality
@@ -0,0 +1,36 @@ | |||
package draginolht65n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much everything is already covered by node_test.go
. Once we add more dragino specific fields we will probably add more to here.
@@ -18,26 +16,28 @@ var Model = resource.NewModel("viam", "lorawan", "node") | |||
|
|||
// Error variables for validation. | |||
var ( | |||
errDecoderPathRequired = errors.New("decoder path is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported these so they could be used in other sensors
meta.json
Outdated
"short_description": "A sensor compoenent for a dragino LHT65N LoRaWAN node." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"short_description": "A sensor compoenent for a dragino LHT65N LoRaWAN node." | |
} | |
"short_description": "A sensor component for a dragino LHT65N LoRaWAN node." | |
} |
And the short_description above too.
@@ -0,0 +1,332 @@ | |||
function decodeUplink(input) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to get it from the github URL in case they make an update? but this is prob fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a decoder from url option! leaving the embed implementation in case someone needs to use it for some reason(no network? idk)
node/node_utils.go
Outdated
|
||
// WriteDecoderFile writes an embeded decoderFile into the data folder of the module. | ||
func WriteDecoderFile(decoderFilename string, decoderFile embed.FS) (string, error) { | ||
// Create or open the file used to save device data across restarts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete or edit comment
if err != nil { | ||
return nil, err | ||
} | ||
n := &LHT65N{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of wrapping the node object I think you could just create a node.Node here, then you could reuse the node's decoderPath field and the Readings/close functions. Just something to consider not 100% sure it would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that initially but ran into some issues with reconfigure. I can't reuse node.Node because the reconfigure function is still using a resource.Config that looks for a node.Config with a decoderPath set. Wrapping the object + adding the helpers lets me get around the issue.
draginolht65n/sensor.go
Outdated
n := &LHT65N{ | ||
Named: conf.ResourceName().AsNamed(), | ||
logger: logger, | ||
// This returns the name given to the resource by user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete or edit comment
draginolht65n/sensor.go
Outdated
|
||
nodeCfg := cfg.getNodeConfig(n.decoderPath) | ||
if len(deps) == 0 { | ||
n.logger.Info("yo no deps") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember to change log before merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah actually meant to delete this one, was using it to debug something
draginolht65n/sensor.go
Outdated
const decoderFilename = "LHT65NChirpstack4decoder.js" | ||
|
||
// Model represents a dragino-LHT65N lorawan node model. | ||
var Model = resource.NewModel("viam", "lorawan", "dragino-LHT65N") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make a model Family since we're going to be using the "viam", "lorawan" module ID a lot of tims
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few nits/questions but lgtm!
conf resource.Config, | ||
logger logging.Logger, | ||
) (sensor.Sensor, error) { | ||
httpClient := &http.Client{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is the only time we use the httpClient could we just create it in the WriteDecoderFileFromURL instead of here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to create the httpClient outside of the function for the mock in testing to work :(
node/node_utils.go
Outdated
|
||
// CheckCaptureFrequency check the resource's capture frequency | ||
// and reports to the user whether a safe value has been configured. | ||
func CheckCaptureFrequency(c resource.Config, interval float64, logger logging.Logger) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the bool return value is ever used, could we get rid of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember the reason why I added it and I didn't write it down, so yeah lets delete it lol
payload = append(payload, netIDLE[:]...) | ||
//nolint:all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tysm for fixing
initial dragino sensor.
big changes
also tweaks the gomod/adds some nolints to prevent the linter from breaking everything