Yun & Compatible
- Details
- Written by Sonny Yu
ATmega32U4 code:
#include <Mailbox.h> int i = 0; void setup() { Bridge.begin(); // Initialize Bridge and Mailbox Mailbox.begin(); Serial.begin(9600); // Initialize Serial while (!Serial); // Wait until a Serial Monitor is connected. } void loop() { Serial.println(i); Mailbox.writeMessage(String(i)); i++; delay(2000); // wait 2 seconds }
AR9331 code:
nano mailbox.py
import socket import json s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 5700)) result = json.loads(s.recv(1024)) print result s.close()
python -u mailbox.py {u'request': u'raw', u'data': u'19'}
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Console Pixel example from IDE:
#include <Console.h> const int ledPin = 13; // the pin that the LED is attached to char incomingByte; // a variable to read incoming Console data into void setup() { Bridge.begin(); // Initialize Bridge Console.begin(); // Initialize Console while (!Console); // Wait for the Console port to connect Console.println("type H or L to turn pin 13 on or off"); pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: } void loop() { // see if there's incoming Console data: if (Console.available() > 0) { incomingByte = Console.read(); // read the oldest byte in the Console buffer: Console.println(incomingByte); if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); // if it's a capital H (ASCII 72), turn on the LED: } if (incomingByte == 'L') { digitalWrite(ledPin, LOW); // if it's an L (ASCII 76) turn off the LED: } } }
Test above code:
ssh root@ yourYunsName.local 'telnet localhost 6571'
type "H" will be on, type "L" will be off.
Now we need redirect port 8888 of Arduino Yun ip (i.e. 192.168.0.102) to localhost 6571.
opkg update opkg install socat
(socat TCP-LISTEN:8888,fork TCP:127.0.0.1:6571) &
Now you should be able access Yun from PC
telnet 192.168.0.102 8888
type "H" will be on, type "L" will be off.
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Install software:
opkg update opkg install php5 php5-cli opkg install php5-mod-sockets opkg install php5-mod-json
Php code:
nano /mnt/sda1/bridge.php
#!/usr/bin/php-cli <?php require ("/usr/lib/php/bridge/bridgeclient.class.php"); $firstValue = $argv[1]; $secondValue = $argv[2]; $thirdValue = $argv[3]; $client = new bridgeclient(); $inputfile="/mnt/sda1/input.csv"; $inputstr=file_get_contents($inputfile); $inputstr="1,2,3"; $client->put("D12",$inputstr); $outputstr=$firstValue.','.$secondValue.','.$thirdValue; $outputfile="/mnt/sda1/output.csv"; file_put_contents($outputfile, $outputstr); ?>
chmod 755 /mnt/sda1/bridge.php
ATmega32u4 code:
#include <Process.h> void setup() { Bridge.begin(); while (!Serial); // do nothing until the serial monitor is opened Serial.println("Start"); } void loop() { Process p; p.begin("/mnt/sda1/bridge.php"); p.addParameter("4"); p.addParameter("5"); p.addParameter("6"); p.run(); char lbuffer[256]; Bridge.get("D12", lbuffer, 256); //Serial.println(lbuffer); String str = String(lbuffer); int commaIndex = str.indexOf(','); int secondCommaIndex = str.indexOf(',', commaIndex + 1); // Search for the next comma just after the first String firstValue = str.substring(0, commaIndex); String secondValue = str.substring(commaIndex + 1, secondCommaIndex); String thirdValue = str.substring(secondCommaIndex + 1); // To the end of the string Serial.println(firstValue); Serial.println(secondValue); Serial.println(thirdValue); delay(1000); }
Write comment (1 Comment)
- Details
- Written by Sonny Yu
Memcached is a general-purpose distributed memory caching system. It could delivery 10~20 time speed boost than Mysql.
opkg update opkg install memcached /etc/init.d/memcached start /etc/init.d/memcached enable
opkg update opkg install python-openssl opkg install distribute easy_install python-memcached
nano /mnt/sda1/memcacheyun.py
#!/usr/bin/python import memcache mc = memcache.Client(['127.0.0.1:11211'], debug=0) mc.set("some_key", "Some value") value = mc.get("some_key") print value mc.set("another_key", 3) mc.delete("another_key") mc.set("key", "1") # note that the key used for incr/decr must be a string. mc.incr("key") print mc.get("key") mc.decr("key") print mc.get("key")
root@Arduino:chmod 755 /mnt/sda1/memcacheyun.py
root@Arduino:/mnt/sda1/memcacheyun.py Some value None 2 1
Write comment (2 Comments)
Subcategories
Expand the Storage at Yun
Expand the Storage at Yun
Languages Supported by Yun
Languages Supported by Yun
Backup and Recover
Backup and Recover
Network and Yun
Network and Yun
Hardware & Yun
Hardware & Yun
OpenWrt-SDK & Yun
OpenWrt-SDK & Yun
Page 6 of 34