Uncategorised
- Details
- Written by Sonny Yu
opkg update opkg install sqlite3-cli opkg install python-sqlite3
sqlite3 /root/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> INSERT INTO sensor_data (temperature) VALUES (40);
sqlite> select * from sensor_data;
sqlite>.quit
nano /root/sensor.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as sqlite
from datetime import datetime
startTime = datetime.now()
for i in range(1000):
con = sqlite.connect('/root/sensor.db')
cur = con.cursor()
cur.execute('select temperature from sensor_data limit 1')
data = cur.fetchone()
#print data[0]
con.close()
print datetime.now() - startTime
chmod 755 /root/sensor.py
root@Arduino:~# /root/sensor.py 0:00:04.430945
Python and Sqlite3 profile speed is 4.43 ms
Write comment (0 Comments)- Details
- Written by Sonny Yu
nano /root/sensor.php
#!/usr/bin/php-cli
<?php
$then = microtime(true);
for ($x = 0; $x <= 1000; $x++) {
$db = new SQLite3('/root/sensor.db');
$result = $db->query('select temperature from sensor_data limit 1') or die('Query failed');
while ($row = $result->fetchArray())
{
$temperature=$row['temperature'];
//echo $temperature."\n";
}
$db->close();
}
$now = microtime(true);
echo ($now-$then)."\n";
?>
chmod 755 /root/sensor.php
root@Arduino:~# /root/sensor.php 4.3555958271
Php and Sqlite3 profile speed is 4.35 ms
Write comment (0 Comments)- Details
- Written by Sonny Yu
nano /www/saveinput.php
<?php $file = 'people.html'; // Open the file to get existing content $current = file_get_contents($file); // Append a new person to the file $current .=$_GET["name"]."\n"; //$current .= "John Smith\n"; // Write the contents back to the file file_put_contents($file, $current); echo "data saved"; ?> <p><a href="/people.html">View Result</a></p> <p><a href="/inputform.html">Input More</a></p>
touch /www/people.html
nano /www/inputform.html
<!DOCTYPE html> <html> <body> <form action="saveinput.php" method="get" target="_blank"> Name: <input type="text" name="name"><br> <input type="submit" value="Submit"> </form> <p>Click on the submit button, and the input will be sent to a page on the server called "saveinput.php".</p> <p> <a href="/people.html">View Result</a></p> </body> </html>
open "http://192.168.0.102/inputform.html" to input data.
Write comment (0 Comments)
- Details
- Written by Sonny Yu
nano /root/console.py
#!/usr/bin/python
import socket
import time
TCP_IP = '127.0.0.1'
TCP_PORT = 6571
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
data = s.recv(BUFFER_SIZE)
s.close()
print "received data:", data
filename=time.strftime("%Y%m%d-%H:%M")+'.log'
print filename
file_ = open(filename, 'w')
file_.write(data)
file_.close()
chmod 755 /root/console.py
ATmega32u4 code:
#include <Console.h>
void setup() {
Bridge.begin(); // Initialize Bridge
Console.begin(); // Initialize Console
}
void loop() {
while (!Console); // Wait for the Console port to connect
int temperature = random(0, 100);
Console.println(temperature);
delay(5000);
}
Testing:
/root/console.py
Revision ATmega32u4 code:
#include <Console.h>
void setup() {
Bridge.begin(); // Initialize Bridge
Console.begin(); // Initialize Console
}
void loop() {
//while (!Console); // Wait for the Console port to connect
if (Console) {
int temperature = random(0, 100);
Console.println(temperature);
}
delay(5000);
}
Thanks ShapeShifter.
http://forum.arduino.cc/index.php?topic=343641.msg2369342#msg2369342
Write comment (0 Comments)
Page 4 of 16