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);
}
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.
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 ?
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.
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.