Uncategorised
- Details
- Written by Sonny Yu
Install Sqlite3:
opkg update opkg install sqlite3-cli sqlite3 /mnt/sda1/sensor.db
sqlite> CREATE TABLE sensor_data(
id INTEGER PRIMARY KEY,
temperature VARCHAR(64),
sqlitetimestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
sqlite> INSERT INTO sensor_data (temperature) VALUES (30);
sqlite> select * from sensor_data;
sqlite>.quit
sqlitetimestamp DATETIME DEFAULT CURRENT_TIMESTAMP, will auto CURRENT_TIMESTAMP.
Php command line:
opkg update opkg install php5-cli php5-mod-sqlite3 nano /mnt/sda1/sensor.php
#!/usr/bin/php-cli
<?php
$db = new SQLite3('/mnt/sda1/sensor.db');
$query = "INSERT INTO sensor_data (temperature) VALUES( ".$argv[1]." )";
$db->exec($query);
$db->close();
?>
chmod 755 /mnt/sda1/sensor.php /mnt/sda1/sensor.php 50
ATmega32u4 code:
#include <Process.h>
void setup() {
Bridge.begin(); // Initialize Bridge
}
void loop() {
int temperature = 50 + random(0, 5);
Process p;
p.begin("/mnt/sda1/sensor.php");
p.addParameter(String(temperature));
p.run();
delay(5000);
}
Write comment (0 Comments)
- Details
- Written by Sonny Yu
opkg update opkg install mysql-server mysql -h192.168.0.20 -uroot -p
mysql> show databases; mysql> CREATE DATABASE ARDUINO; mysql> USE ARDUINO; mysql> CREATE TABLE temperature ( id INT NOT NULL AUTO_INCREMENT, sensor1 VARCHAR(20), sensor2 VARCHAR(20), insert_date TIMESTAMP, PRIMARY KEY (id) ); mysql> SHOW TABLES;
opkg update opkg install python-mysql nano /mnt/sda1/mysql.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import _mysql
import sys, string, os
try:
con = _mysql.connect('192.168.0.20', 'root', 'password', 'ARDUINO')
sqlstr="INSERT INTO temperature(sensor1, sensor2) VALUES( '" + sys.argv[1] +"', '" + sys.argv[2] + "')"
#print sqlstr
con.query(sqlstr)
except _mysql.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
finally:
if con:
con.close()
chmod 755 /mnt/sda1/mysql.py /mnt/sda1/mysql.py 'test1' 'test2'
Arduino code:
#include <Process.h>
int temperature;
void setup() {
Bridge.begin(); // Initialize Bridge
}
void loop() {
int sensor1 = random(0, 100);
int sensor2 = random(0, 10);
Process p;
p.begin("/mnt/sda1/mysql.py");
p.addParameter(String(sensor1));
p.addParameter(String(sensor2));
p.run();
delay(5000);
}
Write comment (0 Comments)
- Details
- Written by Sonny Yu
At MYSQL console:
mysql> CREATE DATABASE sensors; mysql> USE sensors; mysql> CREATE TABLE sensor_data ( -> id INT NOT NULL AUTO_INCREMENT, -> temperature INT, -> insert_date TIMESTAMP, -> PRIMARY KEY (id) -> ); mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'; mysql> FLUSH PRIVILEGES; mysql> INSERT INTO sensor_data (temperature) VALUES(20); mysql> select * from sensor_data;
opkg update opkg install php5-mod-mysqli opkg install php5-cli
nano /mnt/sda1/db.php
#!/usr/bin/php-cli
<?php
$temperature = $argv[1];
$DBServer = '192.168.0.20';
$DBUser = 'root';
$DBPass = 'password';
$DBName = 'sensors';
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
// check connection
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$sql="INSERT INTO sensor_data (temperature) VALUES ($temperature)";
if($conn->query($sql) === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
}
?>
chmod 755 /mnt/sda1/db.php
Send test insert data:
/mnt/sda1/db.php 80
Arduino code:
#include <Process.h>
int temperature;
void setup() {
Bridge.begin(); // Initialize Bridge
}
void loop() {
int temperature = random(0, 100);
Process p;
p.begin("/mnt/sda1/db.php");
p.addParameter(String(temperature));
p.run();
delay(5000);
}
Write comment (2 Comments)
- Details
- Written by Sonny Yu
The latest Yún shield's firmware should be "v2.0.5"
daef7d526145f6e314ea816cae14de5c *dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
Model: Dragino v2 Version: Dragino-v2 common-2.0.5 Build Tue Jul 21 20:24:45 CST 2015
Yun Shield Firmware Change Log
If you have early version like this:
Version: Dragino-v2 common-1.3.4 Build Sat Aug 2 17:35:47 CST 2014
It is time to upgrade.
Upgrading Using the Web Panel
Make sure the Yún shield and your computer are on the same network, and open a browser. Connect to the Yún shield's web panel page by entering the IP address.
Once logged in (default password:dragino), on the first page click upgade, on the upgrade page choose dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin at file system then click Upload buttom.
Upgrading Using the Command Line:
You can connect to the Yún shield via SSH and use a command line tool on your computer to upgrade the system's image.
To connect to your Yún via SSH, open the terminal application of your choice, and enter :
ssh root@ipaddress
cd /tmp/ wget http://www.ibuyopenwrt.com/images/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
md5sum /tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
daef7d526145f6e314ea816cae14de5c /tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
kill-bridge
exec sysupgrade -n "/tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin"
Sending TERM to remaining processes ... sleep uhttpd dbus-daemon dnsmasq thd ntpd link_arduino_ww rcS logger syslogd klogd hotplug2 ubusd netifd Sending KILL to remaining processes ... uhttpd Switching to ramdisk... Performing system upgrade... Unlocking firmware ... Writing from to firmware ... [w] Upgrade completed Rebooting system...Write comment (0 Comments)
Page 10 of 16