Hallo Forum,
ich brauche bitte euere Hilfe.Ich experimentiere mit einer LED Matrix.Es sollen Werte von einen Wechselrichter(Lumentree 600) mit Trucki Stick auf der Matrix angezeit werden.Mqtt Verbindung funktioniert, Werte kommen an und auf der Serial Ausgabe angezeigt.
Aber wie kann ich die einzelnen Werte rausfiltern und einzeln anzeigen(Serial Konsole)?
Zu Beispiel T2SG418981/VBAT - 26.00 zu T2SG418981/VBAT - 26.00 Volt einzeln ?
Grüße-Martin
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <time.h>
#include "Adafruit_GFX.h"
//#include "FreeMonoBold12pt7b.h"
//#include "kongtext4pt7b.h"
#include "PxMatrix.h"
#include <Ticker.h>
#include <MQTTClient.h>
#include <ArduinoJson.h>
// Pins for LED MATRIX
#ifdef ESP32
#define P_LAT 19
#define P_A 23
#define P_B 5
#define P_C 17
#define P_D 18
#define P_E 0
#define P_OE 16
hw_timer_t *timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
#endif
//#include <Ticker.h>
//Ticker display_ticker;
const char *ssid = "******";
const char *password = "*************";
const char MQTT_BROKER_ADRRESS[] = "192.168.2.198"; // CHANGE TO MQTT BROKER'S ADDRESS
const int MQTT_PORT = 1883;
const char MQTT_CLIENT_ID[] = "ESP32MATRIX128"; // CHANGE IT AS YOU DESIRE
const char MQTT_USERNAME[] = "********"; // CHANGE IT IF REQUIRED, empty if not required
const char MQTT_PASSWORD[] = "********"; // CHANGE IT IF REQUIRED, empty if not required
//const char *topic_1 = "T2SG418981/VBAT";
//const char *topic_2 = "T2SG418981/ACSETPOINT";
String topic_1 = "T2SG418981/VBAT";
String topic_2 = "T2SG418981/ACSETPOINT";
const int PUBLISH_INTERVAL = 5000; // 5 seconds
unsigned long lastPublishTime = 0;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
WiFiClient WifiClient;
WiFiClient network;
MQTTClient mqtt = MQTTClient(256);
#define matrix_width 64
#define matrix_height 32
// This defines the 'on' time of the display is us. The larger this number,
// the brighter the display. If too large the ESP will crash
uint8_t display_draw_time = 60; //30-70 is usually fine
PxMATRIX display(128, 32, P_LAT, P_OE, P_A, P_B, P_C, P_D);
// Some standard colors
uint16_t myRED = display.color565(255, 0, 0);
uint16_t myGREEN = display.color565(0, 255, 0);
uint16_t myBLUE = display.color565(0, 0, 255);
uint16_t myWHITE = display.color565(255, 255, 255);
uint16_t myYELLOW = display.color565(255, 255, 0);
uint16_t myCYAN = display.color565(0, 255, 255);
uint16_t myMAGENTA = display.color565(255, 0, 255);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t myCOLORS[8] = { myRED, myGREEN, myBLUE, myWHITE, myYELLOW, myCYAN, myMAGENTA, myBLACK };
#ifdef ESP32
void IRAM_ATTR display_updater() {
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
display.display(display_draw_time);
portEXIT_CRITICAL_ISR(&timerMux);
}
#endif
void display_update_enable(bool is_enable) {
#ifdef ESP32
if (is_enable) {
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &display_updater, true);
timerAlarmWrite(timer, 4000, true);
timerAlarmEnable(timer);
} else {
timerDetachInterrupt(timer);
timerAlarmDisable(timer);
}
#endif
}
void setup() {
Serial.begin(115200); // Initialize serial
display.begin(16);
//display.setMuxDelay(1, 1, 1, 1, 1);
display.setMuxPattern(SHIFTREG_ABC_BIN_DE);
display.setColorOffset(5, 5, 5);
display.setColorOrder(RRGGBB);
display.setMuxDelay(0, 1, 0, 0, 0);
display.setPanelsWidth(2);
//display.setFastUpdate(true);
display.setRotation(0); // we don't wrap text so it scrolls nicely
display.setTextColor(myCYAN);
display.setCursor(2, 0);
display.println("Connecting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
display.print(".");
}
display.setTextWrap(false);
display.clearDisplay();
display.println("");
display.print("WiFi OK");
//display_update_enable(true);
//display.setBrightness(70);
display.clearDisplay();
display.setTextColor(myCYAN);
display.setCursor(2, 0);
display.print("Pixel");
display.setTextColor(myMAGENTA);
display.setCursor(2, 8);
display.print("Time");
display_update_enable(true);
delay(3000);
timeClient.begin();
// print your board's IP address:
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
connectToMQTT();
}
union single_double {
uint8_t two[2];
uint16_t one;
} this_single_double;
unsigned long last_draw = 0;
void scroll_text(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB) {
uint16_t text_length = text.length();
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
display.setTextSize(1);
display.setRotation(0);
display.setTextColor(display.color565(colorR, colorG, colorB));
// Asuming 5 pixel average character width
for (int xpos = matrix_width; xpos > -(matrix_width + text_length * 5); xpos--) {
display.setTextColor(display.color565(colorR, colorG, colorB));
display.clearDisplay();
display.setCursor(xpos, ypos);
display.println(text);
delay(scroll_delay);
yield();
// This might smooth the transition a bit if we go slow
// display.setTextColor(display.color565(colorR/4,colorG/4,colorB/4));
// display.setCursor(xpos-1,ypos);
// display.println(text);
delay(scroll_delay / 5);
yield();
}
}
void scroll_text_2(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB) {
uint16_t text_length = text.length();
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
display.setTextSize(1);
display.setRotation(0);
display.setTextColor(display.color565(colorR, colorG, colorB));
// Asuming 5 pixel average character width
for (int xpos = matrix_width; xpos > -(matrix_width + text_length * 5); xpos--) {
display.setTextColor(display.color565(colorR, colorG, colorB));
display.clearDisplay();
display.setCursor(xpos, ypos);
display.println(text);
delay(scroll_delay);
yield();
// This might smooth the transition a bit if we go slow
// display.setTextColor(display.color565(colorR/4,colorG/4,colorB/4));
// display.setCursor(xpos-1,ypos);
// display.println(text);
delay(scroll_delay / 5);
yield();
}
}
void connectToMQTT() {
// Connect to the MQTT broker
mqtt.begin(MQTT_BROKER_ADRRESS, MQTT_PORT, network);
// Create a handler for incoming messages
mqtt.onMessage(messageReceived);
Serial.print("Arduino UNO R4 - Connecting to MQTT broker");
while (!mqtt.connect(MQTT_CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) {
Serial.print(".");
delay(100);
}
Serial.println();
if (!mqtt.connected()) {
Serial.println("Arduino UNO R4 - MQTT broker Timeout!");
return;
}
// Subscribe to a topic, the incoming messages are processed by messageHandler() function
if (mqtt.subscribe(topic_1))
Serial.print("Arduino UNO R4 - Subscribed to the topic-1: ");
else
Serial.print("Arduino UNO R4 - Failed to subscribe to the topic-1: ");
Serial.println(topic_1);
Serial.println("Arduino UNO R4 - MQTT broker Connected!");
// Subscribe to a topic, the incoming messages are processed by messageHandler() function
if (mqtt.subscribe(topic_2))
Serial.print("Arduino UNO R4 - Subscribed to the topic-2: ");
else
Serial.print("Arduino UNO R4 - Failed to subscribe to the topic-2: ");
Serial.println(topic_2);
Serial.println("Arduino UNO R4 - MQTT broker Connected!");
}
void messageReceived(String &topic, String &payload) {
Serial.println("incoming: " + topic + " - " + payload);
}
uint8_t icon_index = 0;
void loop() {
//scroll_text(15,20,"Welcome to PxMatrix!",96,96,250);
//display.clearDisplay();
mqtt.loop();
if (millis() - lastPublishTime > PUBLISH_INTERVAL) {
lastPublishTime = millis();
}
timeClient.update();
Serial.println(timeClient.getFormattedTime());
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(2, 2);
display.setTextColor(myWHITE);
display.println(timeClient.getFormattedTime());
display.setFont();
}