Arduino-HomeKit-ESP8266 icon indicating copy to clipboard operation
Arduino-HomeKit-ESP8266 copied to clipboard

Log output

Open danilkorotkov opened this issue 3 years ago • 1 comments
trafficstars

There is a problem to make firmware for tuya devices. Tuya uses serial, but this lib uses serial for log and because it is “C” included it is impossible to remap log with ESP8266 UDP cpp library

danilkorotkov avatar Apr 15 '22 04:04 danilkorotkov

this is a little improvement for apps using serial my_logging.h

#ifndef __MY_LOGGING_H__
#define __MY_LOGGING_H__
void my_log(char *);

#endif /* __MY_LOGGING_H__ */

my_logging.cpp

#include <Arduino.h>
#include <WiFiUdp.h>
#include <ESP8266WiFi.h>
WiFiUDP Udp;
IPAddress broadcastIp;
uint16_t  bPort = 2525;

extern "C" {
  #include "my_logging.h"
}

//#define TUYA
//#define TUYA_UDP
//#define TUYA_UDP_SERIAL
//#define UDP_SERIAL

void my_log(char *logtext) {
	#ifdef TUYA
		Serial1.printf(logtext);
		return;
	#endif
	#ifdef TUYA_UDP
		if (WiFi.isConnected()) {
			Udp.beginPacket(broadcastIp,bPort); 
 			Udp.write(logtext); 
  			Udp.endPacket();
		}
		return;
	#endif
	#ifdef TUYA_UDP_SERIAL
		Serial1.printf(logtext);
		if (WiFi.isConnected()) {
			Udp.beginPacket(broadcastIp,bPort); 
 			Udp.write(logtext); 
  			Udp.endPacket();
  		}
  		return;
  	#endif
  	#ifdef UDP_SERIAL
  		printf(logtext);
		if (WiFi.isConnected()) {
			Udp.beginPacket(broadcastIp,bPort); 
 			Udp.write(logtext); 
  			Udp.endPacket();
  		}
  		return;
  	#endif
	printf(logtext);
}

in esp_xpgm.h #define XPGM_PRINTF(fmt, ...) {char *mess = (char*)malloc(sizeof(char) * 200); sprintf_P(mess, PSTR(fmt), ##__VA_ARGS__); my_log(mess); free(mess);}

danilkorotkov avatar Apr 19 '22 15:04 danilkorotkov