Bitte setze Deinen Sketch in Codetags (oben links </> im Foreneditor oder [code] davor und [/code] dahinter - ohne die *).
Das kannst Du auch noch nachträglich durch Editieren tun. Bitte mach das, der Sketch ist besser zu lesen, besonders auf mobilen Geräten.
@fckw
Ich danke dir für deine Anpassung. Ich werde es in Zukunft so machen.
@HotSystems
Das sind die Zugangsdaten des APN. Diese benötige ich nicht.
Ich wolllte ursprünglich diese Library verwenden für den MQTT Connect
Leider habe ich es nicht hinbekommen das SoftSerial zum Arduino Mega HW-Serial umzubauen.
Ich bin dann über die TinyGSM gestolpert.
Angeblich soll man diese ja verwenden können wie die Wifi oder Ethernet Library.
Ich möchte gerne das Cayenne Mydevices Als MQTT-Broker verwenden.
Für Cayenne gibt es eine eigene Library leider nicht in Kombination mit dem Sim800 Modul
Ich bin irgendwie zu blöd diese SoftwareSerial und HW-Serial zu verstehen.
#include "GSM_MQTT.h"
#include <SoftwareSerial.h>
String MQTT_HOST = "test.mosquitto.org";
/*
MQTT host address
*/
String MQTT_PORT = "1883";
/*
MQTT port
*/
SoftwareSerial mySerial(10, 11); // RX, TX
/*
Software Serial through which mqtt events log is printed at 9600 baud rate
*/
void GSM_MQTT::AutoConnect(void)
{
/*
Use this function if you want to use autoconnect(and auto reconnect) facility
This function is called whenever TCP connection is established (or re-established).
put your connect codes here.
*/
connect("qwertyuiop", 0, 0, "", "", 1, 0, 0, 0, "", "");
}
void GSM_MQTT::OnConnect(void)
{
}
void GSM_MQTT::OnMessage(char *Topic, int TopicLength, char *Message, int MessageLength)
{
/*
This function is called whenever a message received from subscribed topics
put your subscription publish codes here.
*/
/*
Topic :Name of the topic from which message is coming
TopicLength :Number of characters in topic name
Message :The containing array
MessageLength:Number of characters in message
*/
mySerial.println(TopicLength);
mySerial.println(Topic);
mySerial.println(MessageLength);
mySerial.println(Message);
}
GSM_MQTT MQTT(20);
/*
20 is the keepalive duration in seconds
*/
void setup()
{
[color=red] // initialize mqtt:
// GSM modem should be connected to Harware Serial
// index =0;[/color]
MQTT.begin();
/*
You can write your code here
*/
}
void loop()
{
/*
You can write your code here
*/
if (MQTT.available)
{
/*
if you want to do something when mqtt connection is live.
You can write your code here
*/
}
MQTT.processing();
}