Sep 17

In-place debugging a Particle Photon

So the question came up, how to debug code on an installed Particle Photon.  Normally I’d use the USB serial port and print statements in the code to direct debugging information to the serial port.  However with my Photon installed in the garage, it’s difficult to debug new code without removing the device to get access to the USB port.  Worse, if the intent is to debug sensors which are physically at the location (in the garage in my case) it’s impossible to debug the sensor code without leaving the Photon physically in place.

So what to do…

The simple answer, debug over WiFi using syslog messages.

You need two things.  The psyslog particle module, and a Syslog server to receive the syslog messages.  I’m using the free Kiwi Syslog .  So limitations to the free Kiwi Syslog version, certainly enough functionality for debugging a Photon device.


Simply include psyslog in your Photon project and add these lines


#include <psyslog.h>

while(!WiFi.ready()) { Particle.process(); }  // have to have WiFi ready before initalizing syslog
syslog_initialize(“n.n.n.n”, 514);                    // use the IP address of your syslog server

then you can add either simply debug statements or more complicated statements to your code as needed.

LOGI(“Car Sensors inited”);


LOGI(String::format(“EOT= %i”,I2CStatus));

The Kiwi Syslog daemon will log all these messages to a file that you can review later (or watch them come in live of the main Syslog screen.  There’s good info included by default in each syslog message such as the line number and the code module inside which the syslog call was made.  A bootup of my Photon produces messages like this:

2017-09-16 19:23:45 User.Info 6c0b84597232 garage-door.ino: 1268 [0000002465] int CheckCar(int, int) — x,y,z= -65,179,25 res=1
2017-09-16 19:23:45 User.Info 6c0b84597232 garage-door.ino: 235 [0000002465] void setup() — States Inited
2017-09-16 19:23:45 User.Info 6c0b84597232 garage-door.ino: 258 [0000002466] void setup() — Vars initalized
2017-09-16 19:23:45 User.Info 6c0b84597232 garage-door.ino: 278 [0000002467] void setup() — Published Vars
2017-09-16 19:23:45 User.Info 6c0b84597232 garage-door.ino: 293 [0000002468] void setup() — Published Functions
2017-09-16 19:23:49 User.Info 6c0b84597232 garage-door.ino: 300 [0000005507] void setup() — Published Hooks
2017-09-16 19:23:52 User.Info 6c0b84597232 garage-door.ino: 333 [0000009346] void setup() — Setup done
2017-09-16 19:27:58 User.Info 6c0b84597232 psyslog: Particle syslog starting

The only problem I’ve had with this is that I’ve seen some dropped syslog messages if you sent too many back to back to back messages.  But other than that, it’s a easy way to get debug statements from your in-place Photon.

Leave a Reply

Your email address will not be published.