MQTT via GPRSBee and a Seeeduino Stalker board

Since many month my combination of the GPRSBee and a Seeeduino Stalker board is running fine. Now I tried to change the transport layer from http to mqtt.

For that I’m trying this code

#include <GPRSbee.h>
#include <Sodaq_MQTT.h>

#define APN "internet.eplus.de"

const int BEEDTR = 12;
const int BEECTS = 13;

static int counter;

void setup()
{
    delay(2000);

    // Set the MQTT server hostname, and the port number
    mqtt.setServer("test.mosquitto.org", 1883);

    // OPTIONAL. Set the user name and password
    //mqtt.setAuth("Hugh", "myPass");

    // Set the MQTT client ID
    mqtt.setClientId("gprsbee_pub_12345");

    /*
     * The transport layer is a GPRSbee
     */
    Serial.begin(9600);

    // pwrkeyPin, vbatPin, statusPin, we use -1 for vbatPin because we have no switched battery here
    gprsbee.initAutonomoSIM800(Serial, BEEDTR, -1, BEECTS);
    // make sure the GPRSbee is switched off to begin with
//    gprsbee.off();

    // Set the APN. You can set the APN user and password too
    gprsbee.setApn(APN);
    // Inform our mqtt instance that we use gprsbee as the transport
    mqtt.setTransport(&gprsbee);
}

void loop()
{
    const char * topic = "SODAQ/demo/text";
    String msg = "Our message, number " + String(counter);
    // PUBLISH something
    if (!mqtt.publish(topic, msg.c_str())) {
	Serial.println("publish failed");
	while (true) {}
    }

    ++counter;
    if (counter >= 10) {
	mqtt.close();
	// End of the demo. Wait here for ever
	while (true) {}
    }

    // Wait a little.
    delay(3000);
}

a slight modification of
https://github.com/SodaqMoja/Sodaq_MQTT/tree/master/examples/gprsbee_pub

running. I have - as always - selected the Arduino Pro Mini for the Seeeduino Stalker as board. But while compiling I get this error message:

Arduino: 1.8.2 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'void MQTT::setTransport(Sodaq_GSM_Modem*)':

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:124:25: error: 'class Sodaq_GSM_Modem' has no member named 'setTCPClosedHandler'

             _transport->setTCPClosedHandler(setMQTTStateClosed);

                         ^

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'bool MQTT::loop()':

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:336:29: error: 'class Sodaq_GSM_Modem' has no member named 'availableMQTTPacket'

     pckt_size = _transport->availableMQTTPacket();

                             ^

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'bool MQTT::isConnected()':

C:\Users\xxx\Documents\Arduino\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:406:24: error: 'class Sodaq_GSM_Modem' has no member named 'isAliveMQTT'

     return _transport->isAliveMQTT();

                        ^

exit status 1
Fehler beim Kompilieren für das Board Arduino Pro or Pro Mini.

Any idea what’s going wrong? Is there any switch depending on the choosen board?

The GPRSbee library implementation / support for the Sodaq_MQTT functions is only partial. Certain methods have not bee implemented yet, and the errors are a reflection of this.

So the example under https://github.com/SodaqMoja/Sodaq_MQTT/blob/master/examples/gprsbee_pub/gprsbee_pub.ino will also not work with the Autonomo?

Is any sketch under https://github.com/SodaqMoja/Sodaq_MQTT/tree/master/examples working with the rev. 6 GPRSBee and the “normal” GPRSBee lib? There is a 3gbee mentioned … is it only for that?

Do I have any chance to use the GPRSBee with MQTT? Is there some code on an other place?

Is https://github.com/SodaqMoja/Sodaq_3Gbee a replacement for the https://github.com/SodaqMoja/GPRSbee? I’m a bit confused, thought that the Sodaq One is a LoRa deivce or was/is ther a GPRS version planed also?

There is also a difference between the Quick example in the documentation section on https://github.com/SodaqMoja/Sodaq_MQTT

#include <GPRSbee.h>
#include <Sodaq_MQTT.h>
#include <Sodaq_MQTT_GPRSbee.h>

and the sketch in the lib’s example directory https://github.com/SodaqMoja/Sodaq_MQTT/blob/master/examples/gprsbee_pub/gprsbee_pub.ino

#include <GPRSbee.h>
#include <Sodaq_MQTT.h>

I can not find any file Sodaq_MQTT_GPRSbee.h is this a typo ir is this file missing in the repository?

A few quick answers:

  1. I believe some of the GPRSbee library examples need updating.
  2. The Sodaq_3Gbee library is for a separate hardware device based on a ublox module.
  3. I’m not sure what the Sodaq_MQTT_GPRSbee library is referring to.

Hi i have the Sodaq Mbili rev 6b with GPRSbee last rev.

i compile this code

#include <GPRSbee.h>
#include <Sodaq_MQTT.h>

static int counter;

void setup()
{
  // We'll use this to print some messages
  Serial.begin(57600);

  // Set the MQTT server hostname, and the port number
  mqtt.setServer("test.mosquitto.org", 1883);

  // OPTIONAL. Set the user name and password
  //mqtt.setAuth("Hugh", "myPass");

  // Set the MQTT client ID
  mqtt.setClientId("gprsbee_pub_1234yighgjh");

  /*
   * The transport layer is a GPRSbee
   */
  // GPRSbee is connected to Serial1 on SODAQ Mbili
  Serial1.begin(9600);
  // This is the code to initialize SODAQ Mbili
  gprsbee.initAutonomoSIM800(Serial1, -1, BEEDTR, BEECTS, 200);


  // Set the APN. You can set the APN user and password too
  gprsbee.setApn("mobile.vodafone.it");
  // Inform our mqtt instance that we use mqtt_gprsbee as the transport
  mqtt.setTransport(&gprsbee);
}


void loop()
{
  const char * topic = "SODAQ/demo/text";
  const char * msg = "Our message";
  // PUBLISH something
  if (!mqtt.publish(topic, msg)) {
    Serial.println("publish failed");
    while (true) {}
  }

  ++counter;
  if (counter >= 10) {
    mqtt.close();
    // End of the demo. Wait here for ever
    while (true) {}
  }

  // Wait a little.
  delay(3000);
}

and i have same error…

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'void MQTT::setTransport(Sodaq_GSM_Modem*)':

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:124:25: error: 'class Sodaq_GSM_Modem' has no member named 'setTCPClosedHandler'

             _transport->setTCPClosedHandler(setMQTTStateClosed);

                         ^

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'bool MQTT::loop()':

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:336:29: error: 'class Sodaq_GSM_Modem' has no member named 'availableMQTTPacket'

     pckt_size = _transport->availableMQTTPacket();

                             ^

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp: In member function 'bool MQTT::isConnected()':

G:\libraries\Sodaq_MQTT-master\src\Sodaq_MQTT.cpp:406:24: error: 'class Sodaq_GSM_Modem' has no member named 'isAliveMQTT'

     return _transport->isAliveMQTT();

                        ^

exit status 1

Please can we have a correct core to publish with MQTT and GPRSbee ?

Thanks

Vittorio

Hi Vittorio,

I do not believe that the implementation of the MQTT functionality, within the GPRSbee library, was every completed. Specifically, the required functionality to work with the Sodaq_MQTT library.

but do you think it is possible to use mqtt with gprsbee?

Not easily. There is the TCP functionality, which can be used to facilitate MQTT.

Thanks Gabriel. Other lib mqtt based on sim800h module can works with last rev of gprsbee?
For example…

Yes you can use that library to create the MQTT messages for you.

In the included example, it has functionality to open the TCP socket and send the message.
However, I would recommend you use the GPRSbee library for that.

In this example

in the software serial

SoftwareSerial GPRS(2, 3); //RX, TX

what is the pin for mbili ?

thanks

You don’t need to use software serial as the Mbili has a second hardware Serial/UART.

The stream object is Serial1.

Ok. Gabriel in grpsbee lib i dont find the example for open tcp connection.

Plese can help me for example code to establish tcp conection with server test.mosquitto.org on port 1883 with gprsbee.h?

Any question. What is the best lib to integrate with gprsbee lib?

I will publish a complete code in this forum for mqtt comunication with mbili and gprsbee.

Thanks gor help.

Here are the related functions in the GPRSbee library:

  bool openTCP(const char *apn, const char *server, int port, bool transMode=false);
  bool openTCP(const char *apn, const char *apnuser, const char *apnpwd,
      const char *server, int port, bool transMode=false);
  void closeTCP(bool switchOff=true);
  bool isTCPConnected();
  bool sendDataTCP(const uint8_t *data, size_t data_len);
  bool receiveDataTCP(uint8_t *data, size_t data_len, uint16_t timeout=4000);
  bool receiveLineTCP(const char **buffer, uint16_t timeout=4000);