Hello, I have used Arduino Uno for a while but is new to Arduino Yun. I followed the instructions listed on the following webpage:
to wirelessly stream my sensor data to a plot under my Plotly account.
Everything goes well except for the timezone. The default timezone is set by the following code in the example sketch:
plotter1.timezone = "America/Montreal";
I tried changing this piece of code but it didn't work. I'm pretty sure that I used the correct timezone string as listed in
arduino-api/Accepted Timezone Strings.txt at master · plotly/arduino-api · GitHub.
I even modified all timezone-related codes in the program - run.py. However, still I cannot implement the desired timezone. Is there anybody once had the same problem and could you give some advice? Thanks.
root@Arduino:~# opkg update
root@Arduino:~# opkg list |grep zoneinfo
zoneinfo-africa - 2011n-1 - Zone Information (Africa)
zoneinfo-asia - 2011n-1 - Zone Information (Asia)
zoneinfo-atlantic - 2011n-1 - Zone Information (Atlantic)
zoneinfo-australia-nz - 2011n-1 - Zone Information (Australia-NZ)
zoneinfo-core - 2011n-1 - Zone Information (core)
zoneinfo-europe - 2011n-1 - Zone Information (Europe)
zoneinfo-india - 2011n-1 - Zone Information (India)
zoneinfo-middleeast - 2011n-1 - Zone Information (MiddleEast)
zoneinfo-northamerica - 2011n-1 - Zone Information (NorthAmerica)
zoneinfo-pacific - 2011n-1 - Zone Information (Pacific)
zoneinfo-poles - 2011n-1 - Zone Information (Arctic, Antarctic)
zoneinfo-simple - 2011n-1 - Zone Information (simple)
zoneinfo-southamerica - 2011n-1 - Zone Information (SouthAmerica)
opkg install zoneinfo-core
opkg install zoneinfo-northamerica
sonnyyu, thanks for your reply.
I tried the commands you suggested, but made no progress.
I have input the command "opkg update" days ago and successfully executed it. Therefore I skipped this command this time.
After inputting "opkg list |grep zoneinfo", I got nothing.
After inputting "opkg install zoneinfo-core", I got the following info:
Unknown package 'zoneinfo-core'.
Collected errors:
- opkg_install cmd: Cannot install package zoneinfo-core.
After inputting "opkg install zoneinfo-northamerica", I got the following info:
Unknown package 'zoneinfo-northamerica'.
Collected errors:
- opkg_install cmd: Cannot install package zoneinfo-northamerica.
Do you have any comment?
streamlet:
I have input the command "opkg update" days ago and successfully executed it. Therefore I skipped this command this time.
You can't do that. You really do need to run "opkg update" before any "opkg install" session. The update process does not store the database for future use, it is short lived.
If you skip the update command, you will get nothing but unknown package errors, exactly as you are reporting.
Thanks, sonnyyu.
Thanks for your clear explanation, ShapeShifter.
I have succeeded in installing the timezone packages. However the problem still exists. In particular, I notice that the timestamp EXACTLY sticks to the UTC timezone, no matter I tried a timezone with UTC+x or UTC-x (x is a integer).
My sketch is attached below (in this example, I use Montreal which falls in the UTC-5 timezone). Any comment?
#include <Wire.h>
#include <Adafruit_HTU21DF.h>
#include <dht.h>
#include <PlotlyYun.h>
#include <YunMessenger.h>
#include <Bridge.h>
#include <Console.h>
// Initialize plotly "plotters" with your stream tokens.
// Find your stream tokens in your plotly account here: https://plot.ly/settings
// Initialize as many plotters as you want! Each plotter will send
// data to the same plot as a separate line.
// Make sure that you place these exact-same stream tokens in your `config.json` file
// on the Linino.
float humidity_DHT22;
float humidity_HTU21D;
#define dht22Pin 4
dht DHT;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
plotly plotter1("plotly streaming token 1");
plotly plotter2("plotly streaming token 2");
void setup() {
pinMode(13, OUTPUT);
if (!htu.begin()) {
digitalWrite(13, HIGH);
}
// start-up the bridge
Bridge.begin();
////
// Uncomment the following 3 lines to start the
// Plotly-Python program on the Linino
// from the Arduino
Process p;
p.runShellCommand("/root/run_plotly.sh");
while (p.running()){ ; } // do nothing until process finishes
delay(2000);
Console.begin();
while (!Console) {
; // wait for Console port to connect.
}
Console.buffer(64);
delay(2000);
plotter1.timezone = "America/Montreal";
plotter2.timezone = "America/Montreal";
}
void loop() {
// Graph data! Place the "y" value that you want to plot
// the "x" value will automatically be a time-stamped value
// Each "plotter" will send data to the same plot as separate lines
DHT.read22(dht22Pin);
humidity_DHT22 = DHT.humidity;
humidity_HTU21D = htu.readHumidity();
plotter1.plot(humidity_DHT22);
plotter2.plot(humidity_HTU21D);
delay(2000);
}
Setup timezone ('America/Montreal') system wide:
uci set system.@system[0].zonename='America/Montreal'
uci set system.@system[0].timezone='EST5EDT,M3.2.0,M11.1.0'
uci commit system
Reboot Yun ( power cycle)
root@Arduino:~# date
Sun Jan 24 13:42:29 EST 2016
sonnyyu, your solution works! Thanks.
Before inputting the commands started with "uci", I checked the timezone using the "date" command, it is found that the default timezone was UTC. This tells why the timezone stuck to the UTC timezone, no matter which timezone I chose in the Arduino sketch.
Based on this observation, I infer that the timezone setting in the Linino part of Arduino Yun has a higher priority over that in the Arduino sketch. In other words, the code "plotter1.timezone = "America/Montreal";" is useless, because the timezone setup is always overridden by the setting in Linino. Am I right?
On the other hand, I think there should be some reason why the code "plotter1.timezone = "America/Montreal";" exists. Maybe there is a way which allows changing the timezone with this code freely with definitions of all timezones pre-installed in Linino. Do you have any idea how to make it?
streamlet:
On the other hand, I think there should be some reason why the code "plotter1.timezone = "America/Montreal";" exists.
I'm not familiar with the library, but I can take a guess. Perhaps setting the time sone in the plotter object is simply telling plotly the time zone of the data stream's time stamps. Seems to me the time zone would need to be known twice: once while generating the time stamp and sending the data (the time zone setting in Linux) and again when plotly is saving the data (the setting in the plotter object.) Is it too far of a stretch of the imagination to think that plotly might be storing the data in their databases as UTC, so it needs to know the time zone of the time stamp to make the correct conversion?
I have sent an email to chris@plot.ly for the operation mechanism behind the timezone setting. I will post the answer here if I got any reply. Thx for your help, sonnyyu and ShapeShifter!