In this tutorial, we will go over several options for logging data during testing and debugging, but also how logging can be used by deployed production-ready products.
This tutorial builds on what you learned in the tutorial Your First Xedge32 Project.
As explained in the introductory tutorial, under the section Understanding the Xedge32 Ecosystem, the Barracuda App Server (BAS) is the foundation for Xedge, which in turn is the foundation for Xedge32. In this tutorial, we will use an Xedge32-powered ESP32 to show how it works, but the tutorial applies to any BAS-powered device.
1 2 3 4 5 6 7 8 9 10 11 12 13 | print (string, ...) -- BAS API trace(string, ...) -- BAS API tracep([info,] priority, string, ...) -- BAS API xedge.elog(op, formatstring, ...) -- Xedge API xedge.eflush([op]) -- Xedge API -- Examples: -- Function print, trace, and tracep convert all arguments to strings trace( "Socket obj:" , ba.socket.connect( "realtimelogic.com" ,80)) -- Uses the same format string as the Lua function string.format xedge.elog({}, "%s %d" , "The Answer to the Ultimate Question of Life is" , 42) |
See the documentation for print,trace,tracep and xedge.elog for details.
Function print, which comes from the Lua API, prints data to the console. However, in a BAS-powered environment, this function, if used from a non LSP page, may not be enabled if the device has no console. When using Xedge32, the output from this function is sent to the trace library. Function trace and tracep send data to BAS’s trace library. The trace library includes a porting layer that, for Xedge32 sends data to the UART serial connection. Function xedge.elog is an Xedge-specific logging function that either sends the message as an email or sends it to the trace library.
The above functions also send data to the TraceLogger, a WebSocket endpoint a TraceLogger client can connect to and receive data from. The Xedge IDE includes a TraceLogger client in the bottom pane. You may also navigate directly to the TraceLogger client by navigating to http://xedge32.local/rtl/tracelogger/.
The TraceLogger Web Client is a JavaScript-powered app that connects to your device using WebSockets. Trace data from the device is then sent over WebSockets to the HTML UI.
Using the TraceLogger Web Client, the trace priority (trace level) can be changed. You can also programmatically change the trace level by controlling the object returned by function ba.create.tracelogger(). When using Xedge, the TraceLogger object is created by the startup code, thus calling ba.create.tracelogger() returns the already created object. The default trace priority set in Xedge is 9.
The trace level for function print and trace is set to zero, the highest priority level. Function xedge.elog’s level is set to 5. Function tracep lets you select any level.
The links below will take you to our online Lua tutorial server, where you can directly interact with the TraceLogger integrated into the Xedge IDE as well as the standalone TraceLogger.
Note that the TraceLogger supports a single active client connection. Should you encounter an error indicating that the TraceLogger is currently in use, you have the option to override this by forcibly disconnecting the existing client and establishing your own connection.
The Mako Server, Xedge32’s big brother, can be used as a TraceLogger client. The benefit of using this option is that it enables a more permanent option for receiving log data from the device. When the Mako Server is installed as a background process, the data received over the network from the device is saved in mako.log, the Mako Server's log buffer. In addition, the Mako Server’s TraceLogger Web Client will show log data in real-time as it trickles in from the device.
Download the Mako Server and the Mako Server’s TraceLogger Client to use this logging option.
For long-term logging, consider installing the Mako Server and the Mako Server’s TraceLogger client on for example, a Raspberry Pi.
Email notifications may feel old-school, but they're handy, both during development and after your product hits the market. That's why Xedge includes a straightforward email logging feature. Configure SMTP in Xedge, and voilà - crucial updates land directly in your inbox.
Email logging acts as your Xedge device's guardian, offering several key benefits:
The tutorial Xedge SMTP Settings explains in detail how to configure SMTP and send emails.
Our extensive tutorials on embedded web servers and IoT are your roadmap to success. But every journey can have its challenges. Our seasoned experts are here to pave the way if you're pressed for time or hit a roadblock. At Real Time Logic, we equip you with knowledge and offer a helping hand when you need it most. Together, let's achieve the extraordinary!