Understanding your data with graphs
Graphs in a RasPiConnect Control Panel
The RasPiConnect, an inexpensive app available for the iPhone and iPad, lets you build control panels for small computers like the Raspberry Pi and Arduino. I have been using this tool for years now and have built more than seven control panels for the Pi and Arduino. The full documentation for RasPiConnect is located on the MiloCreek wiki [12].
Figure 4 shows the Project Curacao control panel with the graph for the Raspberry Pi solar power subsystem. The RasPiConnect interface is built in a file called Local.py
. Building your own responses is easy. You can select virtually any data to send to the RasPiConnect app and display it in a number of ways. Listing 4 is an example of a RasPiConnect Local.py
file for a graph.
Listing 4
Local.py
01 #W-11 is Pi System Status 02 if (objectServerID == "W-11"): 03 04 #check for validate request 05 if (validate == "YES"): 06 outgoingXMLData += Validate.buildValidateResponse("YES") 07 outgoingXMLData += BuildResponse.buildFooter() 08 09 return outgoingXMLData 10 11 # normal response requested 12 13 imageName = "systemstatistics.png" 14 15 responseData = "<html><head>" 16 responseData += "<title></title><style>body,html,\ iframe{margin:0;padding:0;}</style>" 17 responseData += "</head>" 18 19 responseData += "<body><img src="" 20 responseData += Config.localURL() 21 responseData += "static/" 22 responseData += imageName 23 responseData += "" type="jpg" width="800" height="300">" 24 25 responseData +="</body>" 26 27 responseData += "</html>" 28 29 outgoingXMLData += BuildResponse.buildResponse(responseData) 30 31 outgoingXMLData += BuildResponse.buildFooter() 32 return outgoingXMLData
To get a button to select different graphs for the same RasPiConnect control, you write the graph name to a file and then read the file to get the graph to display. Make sure you assign the web control to refresh when you push the button; then, you get an immediate response.
By using a feedback control button to write a file that contains the graph name, you can cycle through different graphs (Listing 5; Figure 5). See my video on the SwitchDoc Labs website for an example [13].
Listing 5
Changing the Graph Display
01 # FB-11 - change the graph display 02 if (objectServerID == "FB-11"): 03 04 #check for validate request 05 # validate allows RasPiConnect to verify this object is here 06 if (validate == "YES"): 07 outgoingXMLData += Validate.buildValidateResponse("YES") 08 outgoingXMLData += BuildResponse.buildFooter() 09 return outgoingXMLData 10 11 # not validate request, so execute 12 13 responseData = "XXX" 14 15 if (objectName is None): 16 objectName = "XXX" 17 lowername = objectName.lower() 18 19 20 if (lowername == "display voltages"): 21 22 responseData = "display currents" 23 responseData = responseData.title() 24 25 26 f = open("./local/GraphSelect.txt", "w") 27 f.write(lowername) 28 f.close() 29 30 31 elif (lowername == "display currents"): 32 33 responseData = "display solar/wind" 34 responseData = responseData.title() 35 36 f = open("./local/GraphSelect.txt", "w") 37 f.write(lowername) 38 f.close() 39 40 elif (lowername == "display solar/wind"): 41 42 responseData = "display voltages" 43 responseData = responseData.title() 44 45 f = open("./local/GraphSelect.txt", "w") 46 f.write(lowername) 47 f.close() 48 49 # defaults to display currents 50 else: 51 lowername = "display currents" 52 f = open("./local/GraphSelect.txt", "w") 53 f.write(lowername) 54 f.close() 55 56 responseData = "display voltages" 57 responseData = lowername.title() 58 59 60 outgoingXMLData += BuildResponse.buildResponse(responseData) 61 outgoingXMLData += BuildResponse.buildFooter() 62 return outgoingXMLData
Conclusion
Displaying data graphically so the user (or customer!) of your program or project can understand key concepts and make informed conclusions is critical. Matplotlib and the Raspberry Pi can make very professional graphs on the fly for lots of applications.
« Previous 1 2 3 4 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)