Hi,
I am new to Arduino environment and have no coding skills. So I apologize if my question is too basic for some of you. I searched the web to find solution for my problem but haven't find anything useful so far.
I would like to write a simple script for my ESP8266 module to handle communication from my MQTT mosquito broker to serial and vice versa.
At this pont my script is able to subscribe to MQTT topic and forward message from that topic(testin) to serial.
My problem is that I do not know how to do the opposite action.
I would like to achive that ESP8266 module would publish new serial message to topic(testout). When I try to verify my current script I get the following error:
invalid conversion from 'byte {aka unsigned char}' to 'const char*' [-fpermissive]
I appriciete any help or advise to make my script work as intended.
Thanks!
Here is copy of my script:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#define wifi_ssid "SSID"
#define wifi_password "PASSWORD"
WiFiClient espClient;
PubSubClient client(espClient);
byte server[] = { xxx, xxx, x, xxx };
byte inByte;
void setup() {
Serial.begin(115200);
delay(100);
WiFi.begin(wifi_ssid, wifi_password);
client.setServer(server, 1883);
client.setCallback(callback);
}
void loop() {
if (!client.connected()) {
while (!client.connected()) {
if (client.connect("tinemqtt")) {
} else
{
delay(5000);}
}
client.publish("testout","ESP8266 is online");
client.subscribe("testin");
}
client.loop();
if (Serial.available()) {
inByte = Serial.read();
client.publish("testout",inByte);
}
}
void callback(char* topic, byte* payload, unsigned int length) {
for (int i = 0; i < length; i++) {
Serial.print((char)payload*);*
- }*
- Serial.println();*
- }*