Graph
A line graph of one or more virtual pins. The server stores the readings, and the graph can show live data or a past day, week, or month.
Set it up on the server
- Sign in to the Box IO dashboard and open the project that uses this device key.
- Turn on Edit.
- In Edit, add Graph.
- Assign the project device key, or set Device on this widget.
- Use Add pin for each virtual pin you want on the chart. Each row is a pin number, a name, and a color. Remove drops one pin. The graph holds up to 16 pins.
- Set Store a reading to one per second, one per minute, or one per hour. One per second is kept 31 days. One per minute is kept 400 days. One per hour is kept 5 years. A new reading in the same period replaces the earlier one.
- Set Live view to the window shown while Live is selected: 1 minute, 15 minutes, 1 hour, 6 hours, 1 day, 1 week, or 1 month.
- Save the layout. Until you save, the server does not store these pins.
- Open Live. Live follows the window you chose. Day shows 24 hours from the date and time you pick. Week shows the Monday-to-Monday week of that date. Month shows that calendar month. Prev and Next move the date.
- Flash the sketch below with the same device key, host, and port
5923. KeepBoxIO.run()inloop().
Properties
Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").
| Property | Where to set it | Format | Example | Effect |
|---|---|---|---|---|
sampleEvery | Dashboard | second, minute, or hour | minute | How often a reading is stored for every pin on this graph. |
liveSpan | Dashboard | minute, 15m, hour, 6h, day, week, or month | hour | How far back the Live button looks. |
graphSeries | Dashboard | Pin, name, and color rows | V4 Temp, V5 Hum | The virtual pins drawn on the chart. Each pin is stored on the device key for this widget. |
label | Dashboard or sketch | Plain text | Pump | Caption above the widget. On a round or oval button this is the caption, not the word on the button face. |
hideLabel | Dashboard | On or off | checked | Hides the caption. Button face text, meter numbers, and label text stay visible. |
fontSize | Dashboard | Whole number 8 to 160, or blank for automatic size | 28 | Text size in pixels inside the widget. |
opacity | Dashboard | 10% to 100% | 70% | Lets an overlapping widget show through. 100% is solid. |
Formatting
- The sketch still uses
virtualWrite. The graph does not need a special call. A number is stored. Text is skipped. - Two writes in the same second, minute, or hour keep the later number.
- Day view starts at the selected time and runs 24 hours. Week view starts Monday at midnight. Month view is the calendar month of the selected date.
- The chart draws at most 720 points for a window, using the last stored reading in each slice.
Sketch
Paste the device key over bx_paste_your_device_key_here. Wi-Fi boards include BoxIOEsp32.h. Ethernet boards use the same calls with an EthernetClient.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
BoxIO.setTimer(1000, sendTemp);
BoxIO.setTimer(1000, sendHum);
}
void loop() {
BoxIO.run();
}
void sendTemp() {
BoxIO.virtualWrite(V4, analogRead(34));
}
void sendHum() {
BoxIO.virtualWrite(V5, analogRead(35));
}
What you should see
After you save the layout, each virtualWrite on those pins leaves one reading at the rate you set. Live shows the recent window. Day, Week, and Month show the stored readings for the date you pick.