|
NetBurner 3.5.8
PDF Version |
Example Path: examples/syslog
This application demonstrates how to use the NetBurner Syslog utility to send logging information to a destination host computer via UDP on port 514. The demo sends a simple counting variable that increments every second to show elapsed time.
It also serves a small web page that reports the live syslog state — current mode, destination, and the number of messages sent so far — rendered on the device as the page is served.
CPPCALL handlerThe application initializes the NetBurner network stack, waits for DHCP configuration to complete, and then begins sending syslog messages every second. Each message contains an incrementing counter showing elapsed seconds since startup.
The application supports two syslog transmission modes:
SysLogAddress is left unset (null), syslog data is sent as a UDP broadcast to 255.255.255.255:514. This works out of the box with no configuration.SysLogAddress is configured, syslog data is sent to the specified IP address on port 514. This is preferred on a busy network.main.cpp uncomment the line // SysLogAddress = AsciiToIp("10.1.1.193"); and replace "10.1.1.193" with your computer's IP address.init(): Initializes the network stackStartHttp(): Starts the web serverWaitForActiveNetwork(): Waits for network connectivityshowIpAddresses(): Displays current IP configurationSysLog(): Sends formatted syslog messagesOnce running, the application will:
Browse to the device's IP address (port 80) to see a live status page. The page uses a <!--CPPCALL ShowSyslogStatus --> tag: the web server hands the HTTP socket to the ShowSyslogStatus() function in main.cpp, which formats the current mode, destination, UDP port, message count, and uptime straight into the page with fdprintf.
The message count and uptime then update once a second without a full page reload: a small piece of JavaScript polls status.html – a second CPPCALL (ShowSyslogData()) that returns just the two changing values as a JSON object – and rewrites them in place. The page is styled with a small self-contained stylesheet (plain CSS, no framework or CDN).
EnableSystemDiagnostics() call for production deploymentsSysLogAddress