In the previous section, we implemented the publishRO() method for a float variable. You might be asking… what did this do for me? How do I see or use them? It would be extremely painful if the paradigm shift of using InqPortal required you to build your entire browser front-end before you could see the results of your work. Fortunately… it doesn’t. In fact, as you get used to using the InqPortal Admin, you might find yourself being weaned from the Arduino IDE’s Serial Monitor altogether. Once you deploy your project to the attic, cellar or high in a tree, there will be no substitute.
Compile and upload your Sketch to your InqPortal server. If you left your browser open to Admin page, you’ll see the Admin will reconnect to your rebooted server. The first thing you’ll note is a new tab – App. By adding any heading(), publishRO() or publishRW() methods, this tab will be created in the Admin. For each method added, you’ll get one row entry in the tab’s table. They’ll stay in the same order as you entered them in your Sketch. As you can see the heading() method simply adds… well… a heading. This heading will show up in one other place as we’ll see in later posts for this tutorial.
As I’m sure, you’ve also noticed, the value is dynamic and is being updated regularly. When the onInterval() callback method runs and your temperature variable is updated, InqPortal detects the change and sends out the updated value. As you can also see, the client (in this case the InqPortal Admin) only knows about the alias ID Temp. It does not know about the Sketch variable temperature. Next up – Recording your numeric published variable with respect to time.
Customizing the Histogram
Another way you can visualize your published data is to add it to the History tab. Earlier in the tutorial, we showed you the History tab and it contained the default set of output (Loop Frequency, Available Memory and Voltage). To track your numeric published variable, first select the drop-down menu and select Configure History. In the entry box, enter a descriptive title that will be used as the Y-axis title and your published variable’s alias ID (Temp) separated by a comma. If you have another published variable you’d like to include, add another Title, ID pair separated by a comma. You can plot as many curves as you like. Other options include selectively adding the system performance metrics, setting a time base and roll-off period and a way of averaging points when otherwise the history gets too cluttered. Press the Configure button when you are satisfied with your options.
By showing your specific project’s published variables in conjunction with the system’s performance metrics, you may identify a stage in your logic that causes the system to be overworked causing the Watch Dogs to take over and reboot your ESP8266. – Bad Dog!
Logging Your Own Information
You might be saying to yourself, “Self… this is all well and good, but I need to see my Serial Output.” When it comes to programming microcontrollers with the Arduino IDE, we do not have a true debugger like most computer programmers are familiar when programming for computers like Windows, Linux and Macs. There are no step-by-step evaluations or break points and certainly no re-revaluating or real-time modifications permitted on an ESP8266. Our only tool is logging values to the Serial Monitor. We have to visualize in our heads what might be going on, add a Serial.printf() method or two dozen, re-compile and verify our expected results. It is a painful way to debug a program. And… just like the Heisenberg Uncertainty Principle, the mere act of viewing (adding that Serial.print() statements) might actually correct the problem or make matters worse. This is especially true with a multi-tasking microcontroller like the ESP8266.
InqPortal can slightly improve on this situation. We’ve discussed this in other areas, but InqPortal has several advantages over the Serial Monitor.
- Using the published methods for you program’s output will also conveniently display the values in the App tab.
- Remote logging so you can still get that vital logging even when your ESP8266 project is high in a tree.
- Remote control of the amount of logging displayed (more below)
- See the logging information from more than one device… even ones without a USB connection.
The LOG() method takes the place of the Serial.printf(). You can still use the Serial versions in your Sketch, and in some cases, you may want to see some output that does not go out across the network. However, LOG() will output to the Serial Monitor AND output to the InqPortal Admin on the Logs tab. The LOG() method has the same set of parameters as the Serial.printf() method, with one addition. The first parameter is the Log Level. It is an integer value between 1 and 255. You can set it to any value you wish, but InqPortal uses the values between 201 and 255. It would be best to avoid these and simply use the lower 200. There are different strategies you can use and it is totally up to you how you set this.
We’ll add a simple example in our FirstPortal project. In our sendTemperature() method, we have added a single LOG message. This way, every time we send out a temperature value from our ESP8266 server, we’ll also be sending out a LOG message to our client(s). We’ve set its Log Level to one. As illustrated below, we can get our output on multiple devices. In this case, browsing in Chrome on Windows and on a Samsung phone.
When doing extensive, long term testing, we can easily find old entries quickly. At each hour, a new heading is placed in the output and the time stamps following the heading displays the minutes, seconds and milliseconds when the message was sent.
Note: The timestamps on the Logs tab are when the message was sent from the server, but relative to the time on your client browser’s computer.
Hint: To clear the screen of entries, you can use a right-click on Windows or long press on your mobile device to activate a popup menu to clear entries. And also to activate/deactivate automatic scrolling.
Remember: You can have multiple browser instances so you can see… say… the Logs tab on one and the App tab on another.
Logging Level
As described above, the first integer parameter of the LOG() function is the Logging Level. You can set it to any value between 1 and 255, but InqPortal uses the values between 201 and 255. This logging level is merely a method to restrict ESP8266 server from sending out certain log messages. It catches the message early in the stack – even before formatting generation. Therefore when filtered out, your ESP8266 doesn’t waste any cycles formatting the printf statement, sending and processing serial output or sending the WiFi message to the clients. Thus, you don’t have to re-compile to regain the performance lost by having a Serial.printf() statement. Set the filtering range on the InqPortal Admin page via the Log Level Range on the Settings tab, then press the Update button. In this example, we’ve restricted to only show those between 2 and 200. This will eliminate all InqPortal messages and the example message we created above.
We’ve completed showing a publishedRO() variable displaying in the App tab and over time via the History tab. We have shown LOGging and optionally restricting output messages to save on ESP8266 processing. Next up, we will show handling the publishRW() version and updating the server from the client side Admin app.