Package: phyphoxBLE
phyphox Micropython BLEUse phyphox to plot sensor data from your Microcontroller.The purpose of this library is to use the phyphox app (seewww.phyphox.org) to plot sensor data on your phone with the open source app phyphox. In the other direction you can also use this library to access sensor data from your phone to use in your ESP32 project withMicropython.Supported boardsESP 32Concept of phyphoxPhyphox is an open source app that has been developed at the RWTH Aachen University. It is available on Android and iOS and primarily aims at making the phone's sensors available for physics experiments. However, the app is based on a very flexible file format that defines data sources, visualizations (i.e. values and graphs) and data analysis (from simple formulas to Fourier transforms). This file format also allows to define Bluetooth Low Energy devices to exchange data from and to.This library generates an experiment configuration in this file format and allows phyphox to conenct to your microcontroller. It directly transfers the configuration (including graph configurations, axis labels, etc.) to phyphox and provides function to submit data to be plotted in phyphox or receive sensor data.Installation[TBD]UsageThe easiest way to learn how to use this library is by looking at the examples in theexamplesfolder. In most cases, you can simply connect to your Microcontroller running this library by scanning for Bluetooth devices via the "+"-button on the main screen of phyphox.randomNumbers.inoThis is our minimal example. It submits random numbers to phyphox. All you need to do to submit a value to phyphox is including this library, starting the server (i.e. insetup()) and writing your data to the server.importphyphoxBLEimporttimeimportrandomdefmain():p=phyphoxBLE.PhyphoxBLE()p.start()#Start the BLE serverwhileTrue:randomNumber=random.randint(0,100)#Generate random number in the range 0 to 100p.write(randomNumber)#Send value to phyphoxtime.sleep_ms(500)#Shortly pause before repeatingif__name__=="__main__":main()CreateExperiment.inoThis example shows how you can set a title, category and description as well as how to define graphs and setting axis labels and units. You can define one or multiple views (shown as tabs in phyphox), each of which can hold one or more graphs.For each graph you need to callsetChannel(x, y)with x and y being an index of your data set. This index corresponds to the order of the values that you transfer in a call toserver.writewhile the index0is special and corresponds to the timestamp at which phyphox receives the value. At the momentserver.writesupports up to five values.For example, let's assume you have the float valuesfooandbar. You can then call server.write(foo, bar) to send a set with both values. If you callsetChannel(0,1), your graph would plotfooon the y axis over time on the x axis. If you callsetChannel(2,1), your graph would plotfooon the y axis andbaron the x axis.Here are some useful methods to create your own experiment:TargetMethodExplanationExperimentsetTitle(String)Sets a title for the experimentExperimentsetCategory(String)Sets a category for the experimentExperimentsetDescription(String)Sets a description for the experimentExperimentaddView(View)Adds a view to the corresponding experimentExperimentaddExportSet(ExportSet)Adds an exportSet to the corresponding experimentViewaddElement(Element)Adds an element to the corresponding viewViewsetLabel(String)Sets a label for the viewGraphsetLabel(String)Sets a label for the graphGraphsetUnitX(String)Sets the unit for x (similar with y)GraphsetLabelX(String)Sets a label for x (similar with y)GraphsetXPrecision(int)Sets the amount of digits after the decimal point (similar with y)GraphsetChannel(int, int)As explained above (1-5)GraphsetStyle(String)Sets the style. For more possibilities check the wikiGraphsetColor(String)Sets the line color of the graph (use a 6 digit hexadecimal code)SeparatorsetHeight(float)Creates a line to separate parts of the experimentSeparatorsetColor(String)Sets the color of the line (use a 6 digit hexadecimal code)InfosetInfo(String)Sets the infotextInfosetColor(String)Sets the font color (use a 6 digit hexadecimal code)ValuesetLabel(String)Sets a label for the displayed valueValuesetPrecision(int)Sets the amount of digits after the decimal pointValuesetUnit(String)Sets a unit for the displayed valueValuesetColor(String)Sets the font color (use a 6 digit hexadecimal code)ValuesetChannel(int)As explained above, just with one parameter (1-5)EditsetLabel(String)Sets label for the editfieldEditsetUnit(String)Sets unitEditsetSigned(bool)true = signed values allowedEditsetDecimal(bool)true = decimal values allowedEditsetChannel(int)As explained above, just with one parameter (1-5)ExportSetsetLabel(String)Sets a label for the exportSet (Used to export to Excel, etc.)ExportDatasetLabel(String)Sets a label for the exportDataExportDatasetDatachannel(int)Defines which channel should be exported for this dataset (1-5)EverythingsetXMLAttribute(String)Custom property e.g. setXMLAttribute("lineWidth="3"")If for some reason the app shows you an error in form of "ERROR FOUND: ERR_X", with different values for X, this could be the reason:ERR_01: The input was too longERR_02: The value exceeds the upper limitERR_03: The input was not a 6-digit hexadecimal codeERR_04: The input does not match with a valid valueIf the microcontroller is continiously rebooting, you maybe added too many elements.getDataFromSmartphone.inoThe phyphox file format is much more powerful than what is offered by this library's interface. In the examplegetDataFromSmartphone.inoyou can see how a phyphox-file can be used to set up a sensor on the phone and retrieve its data on the microcontroller.As the phyphox file format is extremely complex and powerful, please refer to thephyphox wikito learn about it and feel free to contact us if you are stuck or think that a specific aspect of the file format should be easily accessible through our Micropython library.Further documentationFor now, this library is rather lightweight. Feel free to browse the files to learn about the functions that are already available.Missing featuresIn the future we would like to see...Some memory optimizationCompression for the transfer of the phyphox experiment generated on the microcontrollerOption to request a larger mtu sizeAddition graph settingsProper documentationIf you can help with this, we are happy to receive a pull request. You can contact us viacontact@phyphox.orgif you plan on a large addition to this library and want to make sure that it does not collide with anything we are already working on.CreditsThis library has been developed by the phyphox team at the RWTH Aachen University. It is a port of ourArduino BLE libraryand has been developed by Edward Leier and Marcel Hagedorn.ContactContact us any time atcontact@phyphox.organd learn more about phyphox onhttps://phyphox.org.LicenceThis library is released under the GNU Lesser General Public Licence v3.0 (or newer).Note that it uses MicroPython and uses code from its Bluetooth examples (specificallyble_advertising.py, which are licenced under the MIT licence as listed at the end of this readmeThird-party licencesMicroPython is licenced under the MIT licence.The MIT License (MIT)Copyright (c) 2013-2022 Damien P. GeorgePermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.