LassiHeikkila / SIM7000

Go package for using a SimCom SIM7000E NB-IoT raspberry pi hat to send data over a mobile network
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

implement MQTT client #7

Open LassiHeikkila opened 3 years ago

mkyc commented 3 years ago

Hi, since I'm going to try to use MQTT via SIM7000E I was wondering if you had any idea how would you implement this. I might try to help but that is my side project so ... time.

BTW great project, I love it!

LassiHeikkila commented 3 years ago

Hi @mkyc , great to hear that you have interest in this project. It is a hobby project for me so I cannot spend a whole lot of time on it unfortunately. I'm in the process of switching how I execute AT commands from this current handrolled approach to using https://github.com/warthog618/modem to simplify everything.

Anyway, MQTT client should be fairly straightforward to implement, SIMCOM has documented the AT commands quite well: https://www.simcom.com/product/SIM7000X.html You need to create an account, but other than that the documents are available to download from there.

Also Waveshare has some documents available: https://www.waveshare.com/wiki/SIM7000C_NB-IoT_HAT, especially https://www.waveshare.com/w/upload/d/d0/SIM7000_Series_MQTT_Application_Note_V1.00.pdf might be useful.

I have used Paho MQTT library before and I think its done nicely there, so I would like to make the client usage similar to that.

After the AT commands are implemented (we can parse responses to all of them) and we can issue the AT commands correctly, the mqtt client should probably implement something like this at least:

type MqttClient interface{
    Subscribe(topic string, qos byte) error
    Unsubscribe(topic string) error
    SetCallback(cb func(topic string, data []byte)) error
    Publish(topic string, payload []byte, qos byte, retain bool) error
    Disconnect() error // maybe?
    Connect() error // maybe?
}

and have some NewClient(opts ...Option) MqttClient "constructor". Options should set things like broker ip, port, username & password if needed, SSL certs, will topic & payload, clean session, client id and keepalive time.

This https://github.com/warthog618/modem library allows the user to register handlers for async indications from modem and this is how SIM7000X should deliver messages on subscribed topics, so that is how it should be done I think.

Of course its not needed to implement everything right away, starting with the minimal usable content is best.

mkyc commented 3 years ago

Nice! I didn't know that warthog618/modem library. I'll play with it next days. I also had a quick look at Paho MQTT library and I noticed IsConnected() bool method in Client interface which you didn't include in your list. Was there a reason not to put it there?

LassiHeikkila commented 3 years ago

No reason, just forgot. It is useful to have it.