I use this mega 2560 with ESP8266 onboard as MQTT bridge :
http://robotdyn.com/catalog/boards/mega ... micro_usb/
Working fine with RFLink
ESP code example :
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
char* thing = "RFLink"; //MQTT Status messages
char* thing_S = "RFLinkS"; //MQTT RFLink messages
char* Down = "RFLink down!";
char* Alive = "RFLink Alive";
char* Carillon = "10;NewKaku;00aff80e;1;ALLON"; //RFLink send to my doorbell
// Network parameters
const char* ssid = "YourSSID";
const char* password = "YourPassword";
const char* mqtt_server = "ServerIPaddress";
WiFiClient espClient;
PubSubClient client(espClient);
long now, timemqtt = 0;
boolean stringComplete = false;
String inputString = "";
void reconnect()
{
// Loop until we're reconnected
if (!client.connected())
{
//Serial.print("Attempting MQTT connection...");
// Attempt to connect
client.connect(thing,thing,1,false,Down); //Connect MQTT with last will
if (client.connected())
{
//Serial.println("connected");
// Once connected, publish an announcement...
client.publish(thing, Alive);
client.subscribe("Carillon",1);
}
}
}
void callback(char* topic, byte* payload, unsigned int length)
{
if (strcmp(topic,"Carillon")==0)
{
if ((char)payload[0] == '1')
{
Serial.println(Carillon);
}
}
}
void setup()
{
Serial.begin(57600);
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
//Serial.print(".");
}
//Serial.println();
//Serial.print("IP@ : ");
//Serial.println(WiFi.localIP());
//Serial.printf("Mac@ : %s\n", WiFi.macAddress().c_str());
}
void loop()
{
now = millis();
if (!client.connected() && ((now - timemqtt) > 5000))
{
timemqtt = now;
reconnect();
}
if (client.connected())
client.loop();
if (Serial.available())
{
while (Serial.available() && !stringComplete)
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n')
{
stringComplete = true;
}
}
if (stringComplete)
{
const char* msg = inputString.c_str();
client.publish(thing_S, msg);
inputString = "";
stringComplete = false;
}
}
}
RFLink on Mega2560 with ESP8266 onboard as MQTT bridge
Moderators: rtenklooster, Voyager, BertB, Stuntteam
Re: RFLink on Mega2560 with ESP8266 onboard as MQTT bridge
Hi bigfoot.
Nice solution!
What DIP switch settings did you set?
Nice solution!
What DIP switch settings did you set?
Who is online
Users browsing this forum: No registered users and 22 guests