Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Arduino Yun (Linino) software on OpenWrt on 3rd-party devices. TODO: Fully automate install and/or use Linino rootfs image and/or build own firmware using OpenWrt Image Generator. CAVEATS: I have not yet found out how to make the Bridge use Serial (USB) instead of Serial1 (HardwareSerial) for the Leonardo. I have asked a question about t…
opkg install luci-lib-json luci rng-tools usbutils avrdude avahi-daemon
# If rng-tools is not installable, then install it by hand from e.g., http://download.linino.org/linino_distro/linino_dev/latest/packages/rng-tools_3-2_ar71xx.ipk
# Edit your /etc/opkg.conf, add
src/gz barrier_breaker http://download.linino.org/dogstick/all-in-one/latest/packages/
# Comment out your earlier src/gz
opkg update
opkg list|grep bridge
opkg list|grep yun
opkg install -force-overwrite cpu-mcu-bridge yun-conf yun-scripts luci-app-arduino-webpanel gnupg temboo spacebrew uSDaemon
# When no yun shows up in the Arduino IDE, might need to restart avahi-daemon
/etc/init.d/avahi-daemon start
# Need to edit in order to change to correct LED
/usr/bin/blink-start
/usr/bin/blink-stop
rm /tmp/luci-indexcache
# In /etc/avahi/avahi-daemon.conf edit
[server]
enable-dbus=no
# Important; otherwise Arduino IDE will not find the device
chmod a+r /etc/avahi/services/arduino.service
/etc/init.d/avahi-daemon enable
/etc/init.d/avahi-daemon start
SHOULD SHOW
http://192.168.0.15/cgi-bin/luci/webpanel/homepage
# NEED TO GENERATE A GPG KEY -- WHY???
/etc/init.d/generate_new_gpg_key start
# Works only if rngd is there, generates
/etc/arduino/arduino_gpg.asc
/etc/arduino/arduino_gpg.pub
/etc/arduino/arduino_gpg.sec
# Apparently Yun uses avrdude linuxgpio, this is suggested by /etc/linino/test_avrdude.sh
# run-avrdude wants to edit sys/class/gpio/gpio21/value which does not exist here
# Also see http://www.tonylianlong.com/?p=135
# It has modified files for the Arduino IDE and it has the GPG key and gpg binary
# They have also a modified /usr/bin/run-avrdude script which is pure genius, it changes linuxgpio to serial programming and if that is all that is required to change makes it trivial to hook up different boards via USB as well. I have modified it to launch login on ttyACM0 so that Bridge can be launched by the sketch connected to ttyACM0.
# Now launch login on ttyACM0 so that Bridge can be launched by the sketch connected to ttyACM0
/sbin/askfirst ttyACM0 /bin/ash --login
===
Here is how the Bridge gets launched:
Arduino sends enter, then "run-bridge" on the serial port that it is connected to; expecting a login shell there. It appears to me that this is dangerous, since the Arduino has a root shell at its serial port (that we open with "/sbin/askfirst ttyACM0 /bin/ash --login"). Wouldn't it be more sensible to just launch the bridge on the serial port rather than a login shell?
Here is how the Serial Monitor (probably) gets launched:
Arduino IDE connects to root@arduino.local. and runs "ash -c telnet localhost 6571"
In the sketch, just change from "Serial" and use "Console" instead if you want to write to the Serial Monitor. See the ConsoleRead example in the Bridge examples. "Serial" is the serial port on the Arduino while Console is the USB connection going to the Arudino.
===
# Need at least(possibly more) selected parts from full python
# for /usr/bin/run-bridge
root@Yun:~# cp /tmp/usr/lib/python2.7/tty.py /usr/lib/python2.7/
root@Yun:~# cp /tmp/usr/lib/python2.7/tty.py /usr/lib/python2.7/
root@Yun:~# cp /tmp/usr/lib/python2.7/contextlib.py //usr/lib/python2.7/
====
# kmod-fs-hfsplus and kmod-nls-utf8 sufficient to mount Mac devices?
====
For my own reference, these are the packages that come with the YUN according to http://download.linino.org/linino_distro/linino_dev/latest/openwrt-ar71xx-generic-rootfs.tar.gz:
luci-lib-sys kmod-usb-storage terminfo libuci-lua libc opkg triggerhappy kmod-usb-core libpthread ubus iw kmod-crypto-manager luci-mod-admin-core busybox libubus-lua python-json kmod-crypto-hash libiwinfo-lua swconfig kmod-fs-reiserfs libiwinfo libdbus libcurl libdw kmod-lib-crc-ccitt libgpgme luci-theme-openwrt luci-theme-bootstrap kmod-pppoe kmod-video-core libavahi-client kmod-pppox kmod-ipt-conntrack kmod-lib-crc16 base-files kmod-fs-hfsplus netifd uboot-envtools kmod-usb-ohci dnsmasq usbutils luci-sgi-cgi libblkid ubusd libelf1 kmod-spi-gpio python kmod-i2c-core libgpg-error block-mount kmod-fs-vfat kmod-usb2 firewall luci-app-firewall kmod-fs-hfs temboo luci-lib-ipkg libuci liblua libip4tc avahi-dnsconfd libcyassl libdaemon kmod-ath9k libavahi uci lua kmod-fs-ext4 wpad-mini dbus dropbear kmod-ledtrig-timer curl kmod-nls-utf8 kmod-crypto-aes mtd libstdcpp kmod-crypto-core luci-theme-base libjson-c libgcc libreadline libip6tc luci-proto-ppp libffi libuuid luci-mod-admin-full ppp libubox kmod-leds-gpio libusb-1.0 kmod-gpio-button-hotplug gnupg libjson cpu-mcu-bridge luci-lib-web spacebrew librt libassuan kmod-mac80211 libjson-script swap-utils libblobmsg-json iptables hotplug2 kmod-ipt-nathelper kmod-fs-ntfs kmod-fuse jshn libncurses kmod-ipt-core luci-webpanel-linino kmod-ledtrig-default-on rng-tools libpolarssl kmod-ppp kmod-spi-bitbang avahi-daemon uhttpd-mod-lua python-mini kmod-wdt-ath79 avahi-utils libubus uhttpd libxtables avrdude zlib luci-lib-nixio luci-lib-json luci kmod-spi-tty-ds kmod-ath libexpat kernel libnl-tiny libbz2 blkid libusb luci-proto-core px5g kmod-nls-base luci-i18n-english libgdbm yun-scripts libusb-compat uhttpd-mod-ubus uSDaemon wireless-tools kmod-ath9k-common kmod-crypto-arc4 libopenssl kmod-scsi-core kmod-cfg80211 libavahi-dbus-support luci-lib-core ppp-mod-pppoe kmod-spi-dev kmod-ipt-nat kmod-ledtrig-netdev
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_arduino._tcp</type>
<port>80</port>
<txt-record>board=leonardo</txt-record>
<txt-record>distro_version=0.1</txt-record>
</service>
</service-group>
leonardo.name=Arduino Leonardo
leonardo.upload.via_ssh=true
diff -Naur /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge_original/src/Bridge.cpp /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge/src/Bridge.cpp
--- /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge_original/src/Bridge.cpp 2014-02-21 18:07:50.000000000 +0100
+++ /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge/src/Bridge.cpp 2014-01-15 02:58:55.000000000 +0100
@@ -243,6 +243,17 @@
#ifdef __AVR_ATmega32U4__
// Leonardo variants (where HardwareSerial is Serial1)
SerialBridgeClass Bridge(Serial1);
+#elif defined(__AVR_ATmega2560__)
+//Arduino mega,use Serial1,not default Serial0
+SerialBridgeClass Bridge(Serial1);
+#else
+#if defined(USART1_RX_vect)
+//has Serial1
+SerialBridgeClass Bridge(Serial1);
#else
+#ifndef skiponeserial
+#error Your Arduino just have one serial(like UNO),if you want to use the default serial as a bridge,define skiponeserial in the first line.
+#endif
SerialBridgeClass Bridge(Serial);
#endif
+#endif
diff -Naur /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge_original/src/Bridge.h /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge/src/Bridge.h
--- /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge_original/src/Bridge.h 2014-02-21 18:07:50.000000000 +0100
+++ /Users/newuser/Downloads/Arduino Yun Modded.app/Contents/Resources/Java/libraries/Bridge/src/Bridge.h 2014-01-14 16:28:51.000000000 +0100
@@ -96,7 +96,7 @@
// Empty
}
- void begin(unsigned long baudrate = 250000) {
+ void begin(unsigned long baudrate = 115200) {
serial.begin(baudrate);
BridgeClass::begin();
}
#!/usr/bin/python
import sys
import serial
ser = serial.Serial(sys.argv[1], 1200)
ser.close()
#!/bin/sh
#echo 1 > /sys/class/gpio/gpio21/value
#avrdude -c linuxgpio -C /etc/avrdude.conf -p m32u4 -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFB:m -Uflash:w:$1:i $2
#echo 0 > /sys/class/gpio/gpio21/value
#echo "$2" > /s2
echo "" > /dev/ttyACM0
lsusb|grep 0036
if [ "$?"x == "0"x ];then
echo LEONARDO
reset-arduino /dev/ttyACM0
avrdude -V -p atmega32u4 -c avr109 -b 57600 -P /dev/ttyACM0 -C /etc/avrdude.conf -U flash:w:$1 $2
fi
lsusb|grep 0043
if [ "$?"x == "0"x ];then
echo UNO
avrdude -V -p m328p -c arduino -b 115200 -P /dev/ttyACM0 -C /etc/avrdude.conf -U flash:w:$1 $2
fi
lsusb|grep 0042
if [ "$?"x == "0"x ];then
echo MEGA
avrdude -V -C/etc/avrdude.conf -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$1 $2
fi
echo "" > /dev/ttyACM0
# Enable every sketch to communicate with IDE (without the Bridge)
# ser2net -C 6571:raw:0:/dev/ttyACM0:9600
# Enable Bridge
/sbin/askfirst ttyACM0 /bin/ash --login &
@ffissore
Copy link

ffissore commented Mar 30, 2014

GPG is used by the webpanel to encrypt sensitive information (your password and your wifi credential). This is necessary since a typical user will connect using plain http (not being aware of the fact that the yun webserver support https) thus creating a potential security breach.

Loading

@probonopd
Copy link
Author

probonopd commented Mar 30, 2014

Sounds like the web service should ONLY be provided over https, and http requests should be forwarded to https?

Loading

@sangood
Copy link

sangood commented Jun 7, 2014

run-avrdude line 25 maybe:
avrdude -V -C /etc/avrdude.conf -p atmega2560 -c stk500v2 -P /dev/ttyACM0 -b 115200 -D -U flash:w:$1 $2

Loading

@sangood
Copy link

sangood commented Jun 9, 2014

hello,can you tell me why my 703n openwrt can't find /sbin/askfirst ?

Loading

@fredericplante
Copy link

fredericplante commented Sep 28, 2014

Nice script and all, but I got a Easylink M-mini AR9331 module, basicaly the same chip set as Yun, and I would like to know where to begin? Do I have to download some thing first? Where is that file, if so? Thank you for your help.

By the way, i'm totaly new at this. ;)

Loading

@hagope
Copy link

hagope commented Oct 29, 2014

Any idea on how to use SPI for a 3rd party OpenWRT device without the MCU/Bridge? For example, driving a graphics LCD use u8glib.

Loading

@probonopd
Copy link
Author

probonopd commented Dec 23, 2014

See probonopd/poor-mans-yun#2 (Dragino patches to support different Arduino models)

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment