Browse Source

Added optional debug via UDP

fastled
Xose Pérez 7 years ago
parent
commit
8cc1aae248
4 changed files with 76 additions and 5 deletions
  1. +1
    -1
      code/espurna/config/all.h
  2. +7
    -0
      code/espurna/config/arduino.h
  3. +8
    -4
      code/espurna/config/debug.h
  4. +60
    -0
      code/espurna/debug.ino

+ 1
- 1
code/espurna/config/all.h View File

@ -1,10 +1,10 @@
#include "version.h"
#include "arduino.h"
#include "prototypes.h"
#include "debug.h"
#include "general.h"
#include "hardware.h"
#include "sensors.h"
#include "debug.h"
/*
If you want to modify the stock configuration but you don't want to touch


+ 7
- 0
code/espurna/config/arduino.h View File

@ -11,6 +11,13 @@
#define DEBUG_PORT Serial
#endif
// Uncomment and configure these lines to enable remote debug via udpDebug
// To receive the message son the destination computer use nc:
// nc -ul 8111
//#define DEBUG_UDP_IP IPAddress(192, 168, 1, 100)
//#define DEBUG_UDP_PORT 8111
//--------------------------------------------------------------------------------
// Hardware
//--------------------------------------------------------------------------------


+ 8
- 4
code/espurna/config/debug.h View File

@ -1,8 +1,12 @@
#ifdef DEBUG_PORT
#ifndef SONOFF_DUAL
#define DEBUG_MSG(...) DEBUG_PORT.printf( __VA_ARGS__ )
#define DEBUG_MSG_P(...) { char buffer[81]; snprintf_P(buffer, 80, __VA_ARGS__ ); DEBUG_PORT.printf( buffer ); }
#define DEBUG_MESSAGE_MAX_LENGTH 80
#ifdef SONOFF_DUAL
#undef DEBUG_PORT
#endif
#if defined(DEBUG_PORT) | defined(DEBUG_UDP_IP)
#define DEBUG_MSG(...) debugSend(__VA_ARGS__)
#define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__)
#endif
#ifndef DEBUG_MSG


+ 60
- 0
code/espurna/debug.ino View File

@ -0,0 +1,60 @@
/*
DEBUG MODULE
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#include <stdio.h>
#include <stdarg.h>
#ifdef DEBUG_UDP_IP
#include <WiFiUdp.h>
WiFiUDP udpDebug;
#endif
void debugSend(const char * format, ...) {
char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
va_list args;
va_start(args, format);
ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args);
va_end(args);
#ifdef DEBUG_PORT
DEBUG_PORT.printf(buffer);
#endif
#ifdef DEBUG_UDP_IP
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer);
udpDebug.endPacket();
#endif
}
void debugSend_P(PGM_P format, ...) {
char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
char f[DEBUG_MESSAGE_MAX_LENGTH+1];
memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
va_list args;
va_start(args, format);
ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
va_end(args);
#ifdef DEBUG_PORT
DEBUG_PORT.printf(buffer);
#endif
#ifdef DEBUG_UDP_IP
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer);
udpDebug.endPacket();
#endif
}

Loading…
Cancel
Save