Const char* serverName = ersetzen mit IP adresse

Der Original Sketch:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <MFRC522.h>
#include <SPI.h>

#define SS_PIN D8
#define RST_PIN D0

MFRC522 mfrc522(SS_PIN, RST_PIN);

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* serverName = "http://YOUR_SERVER_IP_OR_DOMAIN/insert_rfid.php";

void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();

Serial.println("NodeMCU RFID Reader");
Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Scan a RFID tag...");
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}

String rfid_uid = "";
Serial.print("UID tag :");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
rfid_uid += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
rfid_uid += String(mfrc522.uid.uidByte[i], HEX);
}
rfid_uid.toUpperCase();
Serial.println();
Serial.print("UID String: ");
Serial.println(rfid_uid);

if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String serverPath = serverName + "?rfid_uid=" + rfid_uid;
Serial.println(serverPath);

http.begin(serverPath);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  String payload = http.getString();
  Serial.println(payload);
} else {
  Serial.print("Error code: ");
  Serial.println(httpResponseCode);
}
http.end();

} else {
Serial.println("WiFi Disconnected");
}

delay(3000);
}

Mein angepasster Sketch:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <MFRC522.h>
#include <SPI.h>

#define SS_PIN D8
#define RST_PIN D2

MFRC522 mfrc522(SS_PIN, RST_PIN);

const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* serverName = "http://192.168.1.254/myscript.php";

const char* tempzeit = “AbC|@|cBa“; //Test für Daten später

void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();

Serial.println("NodeMCU RFID Reader");
Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Scan a RFID tag...");
}

void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}

String rfid_uid = "";
Serial.print("UID tag :");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
rfid_uid += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
rfid_uid += String(mfrc522.uid.uidByte[i], HEX);
}
rfid_uid.toUpperCase();
Serial.println();
Serial.print("UID String: ");
Serial.println(rfid_uid);

if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String serverPath = serverName + "?tempzeit=" + tempzeit;
Serial.println(serverPath);

http.begin(serverPath);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  String payload = http.getString();
  Serial.println(payload);
} else {
  Serial.print("Error code: ");
  Serial.println(httpResponseCode);
}
http.end();

} else {
Serial.println("WiFi Disconnected");
}

delay(3000);
}

Bekomme Fehlermeldung beim kompeilern:

C:\Users\ich\AppData\Local\Temp.arduinoIDE-unsaved2025622-1872-1aruzqa.lqar\sketch_jul22a\sketch_jul22a.ino: In function 'void loop()':

C:\Users\ich\AppData\Local\Temp.arduinoIDE-unsaved2025622-1872-1aruzqa.lqar\sketch_jul22a\sketch_jul22a.ino:62:36: error: invalid operands of types 'const char*' and 'const char [11]' to binary 'operator+'
62 | String serverPath = serverName + "?tempzeit=" + tempzeit;
| ~~~~~~~~~~ ^ ~~~~~~~~~~~~
| | |
| const char* const char [11]

exit status 1

Compilation error: invalid operands of types 'const char*' and 'const char [11]' to binary 'operator+'

^ = steht unter dem + bei servername + “=tempzeit