GithubHelp home page GithubHelp logo

Comments (3)

tdack avatar tdack commented on June 3, 2024 1

I worked out what I was doing wrong, := and = are two different things in Go. := initialises a new variable, so in the main function when creating a new mqtt client it was also creating a whole new local variable, however, the helper functions earlier were referencing/pointing at the mqClient variable declared globally. Valuable lesson on variable scopes.

from go-ibbq.

sworisbreathing avatar sworisbreathing commented on June 3, 2024

Hi @danielthrasher - sorry for the delayed response.

No, that thought's never crossed my mind before, but it seems perfectly doable. Neither AWS nor Azure appear to provide an IoT SDK for golang, but paho mqtt has a golang implementation (which is what GCP's golang sample code uses) that you could develop an app against using go-ibbq as a library. Or you could pipe the datalogger output to a python/node/whatever app that does use one of the other IoT SDKs.

from go-ibbq.

tdack avatar tdack commented on June 3, 2024

I just stumbled across this repo and mqtt is one of the things I was looking for. I'm not familiar with Go, however, have managed to get paho.mqtt.golang imported into the datalogger example and connecting to a broker.

Not knowing Go this is where I've come unstuck ...

/* main.go imports and other pre-amble */

/* variable for mqtt client */
var mqClient mqtt.Client

func batteryLevelReceived(batteryLevel int) {
        logger.Info("Received battery data", "batteryPct", strconv.Itoa(batteryLevel))
        token := mqClient.Publish("home/ibqq/battery", 0, false, strconv.Itoa(batteryLevel))
        token.Wait()
}

func main () {
        /* stuff to set up mqtt client */

       mqClient := mqtt.NewClient(opts)

       /* confirm mqtt client has connected to broker */
       /* rest of datalogger example */
}

This compiles fine, runs and connects to the mqtt broker, detects the iBBQ device and then promptly crashes at the first batteryLevelReceived() call

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x277f24]

I suspect that the mqClient variable isn't accessible in batteryLevelRecieved(). Any suggestions on what I'm doing wrong appreciated.

See main.go for all the changes.

from go-ibbq.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.