Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] Daten per Telnet abgreifen.

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Daten per Telnet abgreifen.

    This topic has been deleted. Only users with topic management privileges can see it.
    • capitaenz
      capitaenz last edited by capitaenz

      Hallo zusammen,

      ich habe einen Wemos D1 mit EasyESP.
      EasyESP stellt mit per Telnet Daten vom RX-Pin zur Verfügung.
      Hat jemand eine Idee wie ich die Daten in den ioBroker bekomme?!
      Ich habe zwar diesen Adapter von @Bluefox und @hobbyquaker gefunden:
      https://github.com/ioBroker/ioBroker.telnet
      Jedoch ist er 6 Jahre alt und ohne weitere Beschreibung.

      MightyOhm.JPG

      capitaenz 1 Reply Last reply Reply Quote 0
      • capitaenz
        capitaenz @capitaenz last edited by capitaenz

        Problem gelöst, habe diesen Code gefunden von www.letscontrolit.com
        Damit baut man einfach meine (ursprünglich) gewünschte Serial2MQTT Brücke auf.

        #include <ESP8266WiFi.h>
        #include <PubSubClient.h>
        
        const char* ssid = "SSID";
        const char* password = "PWD";
        const char* mqtt_server = "192.168.XXX.XXX";
        const char* topic_rx = "uart/rx";
        const char* topic_tx = "uart/tx";
        
        
        const byte numChars = 100;
        char receivedChars[numChars]; // an array to store the received data
        boolean newData = false;
        
        WiFiClient espClient;
        PubSubClient client(espClient);
        
        void setup() {
          pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
          Serial.begin(9600);
          setup_wifi();
          client.setServer(mqtt_server, 1885);
          client.setCallback(callback);
        }
        
        void setup_wifi() {
          delay(10);
          WiFi.begin(ssid, password);
          while (WiFi.status() != WL_CONNECTED) {
            delay(500);
          }
        }
        
        void callback(char* topic, byte* payload, unsigned int length) {
          for (int i = 0; i < length; i++) {
            Serial.print((char)payload[i]);
          }
          Serial.println();
        }
        
        String macToStr(const uint8_t* mac)
        {
          String result;
          for (int i = 0; i < 6; ++i) {
            result += String(mac[i], 16);
            if (i < 5)
              result += ':';
          }
          return result;
        }
        
        void reconnect() {
          String clientName;
          clientName += "esp8266-";
          uint8_t mac[6];
          WiFi.macAddress(mac);
          clientName += macToStr(mac);
          clientName += "-";
          clientName += String(micros() & 0xff, 16);
          while (!client.connected()) {
            if (client.connect((char*) clientName.c_str())) { // random client id
              digitalWrite(BUILTIN_LED, LOW); // low = high, so this turns on the led
              client.subscribe(topic_rx); // callback: mqtt bus -> arduino
            } else {
              digitalWrite(BUILTIN_LED, HIGH); // high = low, so this turns off the led
              delay(5000);
            }
          }
        }
        
        void loop() {
          if (!client.connected()) {
            reconnect();
          }
          client.loop();
        
          recvWithEndMarker();
          showNewData();
        }
        
        void recvWithEndMarker() {
          static byte ndx = 0;
          char endMarker = '\n';
          char rc;
         
          while (Serial.available() > 0 && newData == false) {
            rc = Serial.read();
        
            if (rc != endMarker) {
              receivedChars[ndx] = rc;
              ndx++;
              if (ndx >= numChars) {
                ndx = numChars - 1;
              }
            }
            else {
              receivedChars[ndx] = '\0'; // terminate the string
              ndx = 0;
              newData = true;
            }
          }
        }
        
        void showNewData() {
          if (newData == true) {
            client.publish(topic_tx, receivedChars); // publish: arduino -> mqtt bus
            newData = false;
          }
        }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        Support us

        ioBroker
        Community Adapters
        Donate

        445
        Online

        31.8k
        Users

        80.0k
        Topics

        1.3m
        Posts

        communication
        1
        2
        151
        Loading More Posts
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes
        Reply
        • Reply as topic
        Log in to reply
        Community
        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
        The ioBroker Community 2014-2023
        logo