
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
github.com/jcodybaker/go-shelly
go-shelly is an unofficial native go client for the Shelly Gen2 API. It compliments the MongooseOS mgrpc library.
This library is currently in active development (as of December 2024). It has meaningful gaps in testing and functionality. At this stage there is no guarantee of backwards compatibility. Once the project reaches a stable state, I will begin crafting releases with semantic versioning.
In most cases, using the library is as simple building an RPC channel and calling .Do(). See the go doc and Shelly Gen2 API documentation.
import (
"context"
"fmt"
"log"
shelly "github.com/jcodybaker/go-shelly"
"github.com/mongoose-os/mos/common/mgrpc"
)
const (
rpcAddr = "http://192.168.1.20/rpc"
)
func main() {
ctx := context.Background()
c, err := mgrpc.New(ctx, rpcAddr, mgrpc.UseHTTPPost())
if err != nil {
log.Fatalf("establishing rpc channel: %v", err)
}
defer c.Disconnect(ctx)
req := &shelly.ShellyGetStatusRequest{}
statusResp, _, err := req.Do(ctx, c)
if err != nil {
log.Fatalf("querying device status: %v", err)
}
for i, sw := range statusResp.Switches {
fmt.Printf("Switch %d status: %v\n", i, *sw.Output)
}
}
null
. For example, in some cases (ex. Wifi.SetConfig), a JSON key with null
value will clear the existing configuration, while omitting the key/value entirely leaves it untouched.Pull-requests and issues are welcome. Code should be formatted with gofmt, pass existing tests, and ideally add new testing. Test should include samples from live device request/response flows when possible.
This library and its authors (Cody Baker - cody@codybaker.com) have no affiliation with Allterco Robotics (the maker of Shelly devices) or Cesanta Software Limited (the maker of MongooseOS). All trademarks are property of their respective owners. Importantly, the "Shelly" name and names of devices are trademarks of Allterco Robotics. MongooseOS and related trademarks are property of Cesanta Software Limited.
By downloading/using this open-source library you indemnify the authors of this project (J Cody Baker) from liability to the fullest extent permitted by law. There are real risks of fire, electricution, and/or bodily injury/death with these devices and connected equipment. Errors, bugs, or misinformation may exist in this software which cause your device and attached equipment to function in unexpected and dangerous ways. That risk is your responsibility.
Copyright 2024 J Cody Baker and licensed under the MIT license.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.