1. Make sure you install the dropbox module first of course, 

opkg update
opkg install python-openssl #adds ssl support to python
opkg install distribute #it contains the easy_install 
easy_install dropbox

2. Create an app under your own dropbox account in the "App Console". (https://www.dropbox.com/developers/apps)

3. Just for the record I created my App with the following:

  1. App Type as "Dropbox API APP".
  2. Type of data access as "Files & Datastores"
  3. Folder access as "My app needs access to files already on Dropbox". (ie: Permission Type as "Full Dropbox".)

4. Then click the "generate access token" button and cut/paste into the python example below in place of :

http://stackoverflow.com/questions/23894221/upload-file-to-my-dropbox-from-python-script

nano /mnt/sda1/uploaddropbox.py
#!/usr/bin/python
import dropbox
#client = dropbox.client.DropboxClient(<auth_token>)
client = dropbox.client.DropboxClient("P9wJXJRuXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX9hmHMlLUQbWI")
print 'linked account: ', client.account_info()
f = open('/mnt/sda1/test.wav', 'rb')
response = client.put_file('/test.wav', f)
print 'uploaded: ', response
chmod 755 /mnt/sda1/uploaddropbox.py
/mnt/sda1/uploaddropbox.py

 

 

Write comment (0 Comments)

Install MQTT:

opkg update
opkg install mosquitto
opkg install mosquitto-client
/etc/init.d/mosquitto restart

Subscribing to a Topic:

mosquitto_sub -d -t hello/world
Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0

Publishing to a Topic, open second terminal windows:

mosquitto_pub -d -t hello/world -m "Hello World"
Received CONNACK
Sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (11 bytes))

at first windows you should see:

Received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (11 bytes))
Hello World

Python code:

opkg update
opkg install libmosquitto
opkg update
opkg install python-openssl #adds ssl support to python
opkg install distribute #it contains the easy_install command line tool (this can take some time)
easy_install pip #installs pip  (this can take some time)
pip install mosquitto
nano /mnt/sda1/temperature.py
#!/usr/bin/python
import mosquitto
import sys
mqttc = mosquitto.Mosquitto("python_pub")
mqttc.connect("127.0.0.1", 1883, 60, True)
mqttc.publish("hello/temperature", sys.argv[1] )
chmod 755  /mnt/sda1/temperature.py
/mnt/sda1/temperature.py 34

open second terminal windows:

mosquitto_sub -d -t hello/temperature

to confirm temperature sent.

ATmega32u4 code:

#include <Process.h>
void setup() {
  Bridge.begin();   // Initialize Bridge
}
void loop() {
  int temperature = random(0, 100);
  Process p;        // Create a process and call it "p"
  p.begin("/mnt/sda1/temperature.py");   // Process that launch the  command
  p.addParameter(temperature); // pass  parameter 
  p.run();      // Run the process and wait for its termination
  delay(5000);
}

 

 

Write comment (1 Comment)

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> INSERT INTO sensor_data (temperature) VALUES (40);

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

sqlite3 /mnt/sda1/sensor.db

sqlite> select * from sensor_data;

confirm insert is OK.

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)

Use str(datetime.now()):

touch /mnt/sda1/datalog.csv
nano /mnt/sda1/datalog.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from datetime import datetime
data_rcv=sys.argv[1] +"," + sys.argv[2] +"," + str(datetime.now())
f = open('/mnt/sda1/datalog.csv','a')
f.write(data_rcv)
f.write('\n')
f.close()
chmod 755 /mnt/sda1/datalog.py

Testing:

/mnt/sda1/datalog.py '1' '2'

ATmega32u4 code:

#include <Process.h>
void setup() {
 Bridge.begin(); // Initialize Bridge
}
void loop() {
 Process p;              
 p.begin("/mnt/sda1/datalog.py");      
 p.addParameter("1"); 
 p.addParameter("2"); 
 p.run();
 delay(10000);
}

 

 

Write comment (0 Comments)

Subcategories

Expand the Storage at Yun

Languages Supported by Yun

Backup and Recover

Network and Yun

Hardware & Yun

OpenWrt-SDK & Yun