Hallo Zusammen,
ich habe die Verbindung zwischen dem Keypad Amazon Link und dem Wemos hinbekommen. Im Monitor sehe ich die gedrückten Zahlen
Nun habe ich bisher folgenden Code zusammen kopiert:
#include <ESP8266WiFi.h>
#include <Keypad.h>
#include <PubSubClient.h>
const char* ssid = "xxx";
const char* password = "xxxx";
const char* mqttServer = "192.168.0.222";
const int mqttPort = 1883;
const char* mqttUser = "xxx";
const char* mqttPassword = "xxx";
WiFiClient espClient;
PubSubClient client(espClient);
const byte n_rows = 4;
const byte n_cols = 4;
char keys[n_rows][n_cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte colPins[n_rows] = {D3, D2, D1, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
client.setServer(mqttServer, mqttPort);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
Serial.println("connected");
} else {
Serial.print("failed with state ");
Serial.print(client.state());
delay(2000);
}
}
client.publish("esp/test", "Hello from ESP8266");
client.subscribe("esp/test");
}
void loop(){
char myKey = myKeypad.getKey();
if (myKey != NULL){
Serial.print("Key pressed: ");
Serial.println(myKey);
}
}
Die Verbindung zum WLAN wird aufgebaut ( sehe ich in der Fritzbox ) und der Text "Hello from ESP8266" wird per MQTT gesendet ( das sehe ich in iobroker ). Nun möchte ich aber die Tasteneingaben als MQTT an iobroker senden und ich dachte mir machst einfach:
void loop(){
char myKey = myKeypad.getKey();
if (myKey != NULL){
Serial.print("Key pressed: ");
Serial.println(myKey);
client.publish("esp/test", myKey);
}
}
Das geht aber leider nicht, folgende Meldung kommt:
invalid conversion from 'char' to 'const char*' [-fpermissive]
Ich ersuche gerade Tante Google um Rat aber noch komme ich nicht weiter.