Una delle caratteristiche più comode di Arduino Yun è la possibilità di caricare sketch via rete, direttamente dall’IDE (come vi ho mostrato in un precedente tutorial). L’IDE di Arduino utilizza il protocollo Bonjour (porta UDP 5353) per cercare le schede Yun presenti in rete: questa modalità di auto-discovery funziona bene in rete locale ma non su Internet.
Il progetto di oggi vi consente di fare l’upload di un nuovo sketch tramite una pagina web protetta, facilmente accessibile anche via Internet.
Descrizione
Il processo di upload di un nuovo sketch effettuato dall’IDE è il seguente (grazie alle spiegazioni di Federico Fissore sul forum):
[checklist]
- copia (via SCP) la versione compilata (.hex) dello sketch su Arduino Yun
- aggiunge il bootloader (comando merge-sketch-with-bootloader.lua)
- programma il microcontrollore ATMega32u4 (comando run-avrdude)
[/checklist]
Ho sviluppato una applicazione in PHP che effettua le operazioni sopra elencate; per questioni di sicurezza l’applicazione è protetta da password (la stessa utilizzata per accedere a Yun via SSH o per l’upload via IDE).
Ringraziamenti
Per prima cosa mi fa piacere ringraziare:
- jQuery, libreria utilizzata per le chiamate Ajax
- jQuery File Upload Plugin, utilizzato per l’upload della versione compilata dello sketch
- nuoveXT iconset, da cui ho preso le icone
Prerequisiti
La parte server di Yun Sketch Uploader è sviluppata in PHP: perché possa essere eseguita da Linino è necessaria l’installazione di alcuni pacchetti; installazione che può essere fatta tramite la WebGUI o via terminale.
Per prima cosa ricordatevi di aggiornare l’elenco dei pacchetti disponibili:
opkg update
quindi installiamo php5 e il modulo CGI per l’utilizzo dal webserver uHttpd:
opkg install php5 php5-cgi
sono necessari anche alcuni moduli aggiuntivi:
opkg install php5-mod-json php5-mod-hash php5-mod-session
Infine configuriamo uHttpd come spiegato qui.
Installazione
I files che compongono il progetto sono disponibili nel mio repository Github.
Utilizziamo il pulsante Download ZIP per scaricarli in un unico archivio:
Estraiamo l’archivio in una cartella sul nostro disco fisso (es. sul disco C). Spostiamo quindi la cartella sulla scheda SD, nel percorso arduino\www e rinominiamola in sketchUploader:
Inseriamo la scheda SD nel nostro Yun e proviamo a collegarci all’indirizzo http://yun_ip/sd/sketchUploader/
Se l’installazione ha avuto successo, dovrebbe apparire la maschera di login di sketchUploader:
Nella prossima pagina vedremo come utilizzarlo…
Bravo. Adesso torna su CBC 😉
“08 visitor(s) online”
fai tornare su CBC anche gli altri 7
😉
This is so cool! Great work!
Is it possible to copy/padte the .hex path into the uploaded (instead of navigating to file) since this path changes erverytime… and we have to get this path from IDE window anyway?
Hi Michael,
thanks! it requires some changes in the javascript code to add a text box where you can paste the path of the hex file… but of course you can paste it in the “open file” dialog instead of navigating to file.
Hi Luca,
I found a strange behavior… sketchUploader loads and reboots Yun… but the code is not actually changes. I get errors like this.. when uploading via ethernet or with sketchUploader. Wifi and usb work just fine. Have you seen this before?
====================
vrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
/usr/bin/run-avrdude: line 4: can’t open /tmp/efuse: no such file
rm: can’t remove ‘/tmp/efuse’: No such file or directory
sh: 203: unknown operand
====================
Hi Michael,
that’s strange, it seems the “linux” part of the Yun can’t communicate with the atmega32u4… are you able to upload sketches using the Arduino IDE via wifi?
Hi Luca,
I use 1.5.6-r2 IDE, and recently updated the firmware to the latest from Arduino.
Wifi and usb upload work fine. I think sketchUploader worked fine at first (confusing now)… but sketchUploader and ethernet definitely don’t work now on multiple Yun modules.
Still scratching my head. I really like your sketchUploader.. it should be a standard package that makes the Yun so much better!
Is it possible for the Yun to fetch the upgrade from a remote website and then do the sketch update? This would avoid the need to access the Yun from a remote site when it is likely behind a firewall.
Tom
Hi Tom!
Of course you can write a script that fetches (via wget, http://ftp...) the new sketch and run the commands to program the ATMega… you gave me the idea for a new blog post 😉
Hi!!
Firstly, thanks for your work, the project is amazing and very useful for arduino.
I have been done everything you say in this post and even tried the php example webpage with success, but once I tried with the sketchUploader webpage it appeared with a white background and a simple style.
I have tried that webpage on my computer and even with the dreamweaver editor and it seems that it is a problem of the webpage directly. Have anyone tried to the las update of this project? I downloaded it from the official repository.
Anyway, thanks a lot for your job luca!!
Sorry, there’s an error in the last post. I wanted to say “I have done” in spite of “I have been done”.
Hi Gabriel… could it be that you didn’t install PHP (or one of its required modules) on the Yun? Anyway, did you notice that the latest official images include a “built-in” sketch upload feature?
I get the sketchuploader page but why does it just sit there after I enter arduino for the password?
Hi Jeff,
very strange, did you install PHP and all the requires packages? Anyway, the new version of Linino do include a “builtin” function to upload sketches, did you try it?
yes all packages confirmed installed. Can I install the latest linino from 5 days ago or do I need the arduino one for my yun? thank you!!
Download the latest OpenWRT image from http://www.arduino.cc/en/Main/Software#toc8
ok all upgraded ran all steps from scratch, I can connect to http://192.168.1.33/sd/sketch/index.html
and I type in arduino for the password, click on log in but nothing happens, what may I be missing? thx again for helping!