Skip to content

Commit d1ab830

Browse files
author
Federico Fissore
committed
Upload sketch: added "upload sketch" form for uploading a precompiled sketch on the 32u4
Releasing version 1.4
1 parent 85f1979 commit d1ab830

File tree

10 files changed

+642
-434
lines changed

10 files changed

+642
-434
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Once done, copy the files back to your pc and submit us a [pull request](https:/
2020

2121
## Development: the fast, local but hard way
2222

23-
You need a GNU/Linux box and the following tools: `subversion`, `gnupg`, `lua`, `make`, `gcc`, `wget`. On Debian based distros, these are packages `subversion`, `gnupg`, `lua5.1`, `build-essential`, `wget`.
23+
You need a GNU/Linux box and the following tools: `subversion`, `gnupg`, `lua`, `make`, `gcc`, `wget`. On Debian based distros, these are packages `subversion`, `gnupg`, `lua5.1`, `liblua5.1-0-dev`, `build-essential`, `wget`.
2424

2525
Open the terminal and type
2626
```bash
2727
sudo mkdir /etc/arduino
2828
cd /etc/arduino
29-
sudo wget https://raw.github.com/arduino/linino/master/trunk/package/linino/yun-conf/files/etc/arduino/gpg_gen_key_batch
29+
sudo wget https://raw.githubusercontent.com/arduino/openwrt-packages-yun/master/arduino/yun-conf/files/etc/arduino/gpg_gen_key_batch
3030
sudo gpg --batch --gen-key /etc/arduino/gpg_gen_key_batch
3131
sudo rm -f /etc/arduino/arduino_gpg.asc
3232
sudo gpg --no-default-keyring --secret-keyring /etc/arduino/arduino_gpg.sec --keyring /etc/arduino/arduino_gpg.pub --export --armor --output /etc/arduino/arduino_gpg.asc

package.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PREFIX=`basename $SOURCE_FOLDER`
1111

1212
cd ..
1313

14-
VERSION=1.3
14+
VERSION=1.4
1515

1616
tar --transform "s|$PREFIX/|luci-app-arduino-webpanel-$VERSION/|g" -cjv -f luci-app-arduino-webpanel-$VERSION.tar.bz2 \
1717
$PREFIX/www/index.html \

uglify_assets.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ for js in aes-enc base64 mouse PGencode PGpubkey rsa sha1; do
1313
rm -f $js.ugly.js
1414
done
1515

16-
uglifycss style.css > style.ugly.css
16+
uglifycss style.css > style.ugly.css

usr/lib/lua/luci/controller/arduino/index.lua

+38-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ local function lines_from(file)
4343
return lines
4444
end
4545

46-
--[[
4746
local function rfind(s, c)
4847
local last = 1
4948
while string.find(s, c, last, true) do
5049
last = string.find(s, c, last, true) + 1
5150
end
5251
return last
5352
end
54-
]]
5553

5654
local function param(name)
5755
local val = luci.http.formvalue(name)
@@ -209,6 +207,7 @@ function index()
209207
make_entry({ "webpanel", "rebooting" }, template("arduino/rebooting"), nil)
210208
make_entry({ "webpanel", "reset_board" }, call("reset_board"), nil)
211209
make_entry({ "webpanel", "toogle_rest_api_security" }, call("toogle_rest_api_security"), nil)
210+
make_entry({ "webpanel", "upload_sketch" }, call("upload_sketch"), nil)
212211

213212
--api security level
214213
local uci = luci.model.uci.cursor()
@@ -600,6 +599,43 @@ function toogle_rest_api_security()
600599
uci:commit("arduino")
601600
end
602601

602+
function upload_sketch()
603+
local sketch_hex = "/tmp/sketch.hex"
604+
605+
local chunk_number = 0
606+
607+
local fp
608+
luci.http.setfilehandler(function(meta, chunk, eof)
609+
if not fp then
610+
fp = io.open(sketch_hex, "w")
611+
end
612+
if chunk then
613+
chunk_number = chunk_number + 1
614+
fp:write(chunk)
615+
end
616+
if eof then
617+
chunk_number = chunk_number + 1
618+
fp:close()
619+
end
620+
end)
621+
622+
local sketch = luci.http.formvalue("sketch_hex")
623+
if sketch and #sketch > 0 and rfind(sketch, ".hex") > 1 then
624+
local merge_output = luci.util.exec("merge-sketch-with-bootloader.lua " .. sketch_hex .. " 2>&1")
625+
local kill_bridge_output = luci.util.exec("kill-bridge 2>&1")
626+
local run_avrdude_output = luci.util.exec("run-avrdude /tmp/sketch.hex '-q -q' 2>&1")
627+
628+
local ctx = {
629+
merge_output = merge_output,
630+
kill_bridge_output = kill_bridge_output,
631+
run_avrdude_output = run_avrdude_output
632+
}
633+
luci.template.render("arduino/upload", ctx)
634+
else
635+
luci.http.redirect(luci.dispatcher.build_url("webpanel/homepage"))
636+
end
637+
end
638+
603639
local function build_bridge_request(command, params)
604640

605641
local bridge_request = {

usr/lib/lua/luci/view/arduino/homepage.htm

+30
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,36 @@ <h3><% if data["pretty_name"] then %><%= data["pretty_name"] %> (<%= name %>)<%
140140
</div>
141141
<% end %>
142142

143+
<div class="wrapper divide">
144+
<h3>Upload sketch</h3>
145+
<p class="description">Select a <strong>.hex</strong> file (compiled sketch) and upload it on the microcontroller of this Y&uacute;n.
146+
<br>
147+
For more information about how to obtain the <strong>.hex</strong> file of your sketch, visit <a target="_blank" href="http://arduino.cc/en/Hacking/BuildProcess">this page</a>.
148+
</p>
149+
<p>
150+
<form method="post" action="<%= pcdata(controller .. '/webpanel/upload_sketch') %>" enctype="multipart/form-data">
151+
<ul>
152+
<li>
153+
<div class="input_container">
154+
<input id="sketch" name="sketch_hex" type="file">
155+
</div>
156+
<p><br/></p>
157+
</li>
158+
<li>
159+
<div class="input_container">
160+
<input id="upload_button" class="btTxt submit saveForm" type="submit" name="button" value="Upload">
161+
</div>
162+
</li>
163+
<li id="progress_bar_upload" style="display: none">
164+
<div class="progress_bar_upload blue_arduino stripes">
165+
<span style="width: 100%"></span>
166+
</div>
167+
</li>
168+
</ul>
169+
</form>
170+
</p>
171+
</div>
172+
143173
<!--
144174
<div class="wrapper divide" id="www">
145175
<div id="currsketch">
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<%
2+
local http = require("luci.http")
3+
http.prepare_content("text/html; charset=utf-8")
4+
-%>
5+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6+
<!--
7+
This file is part of YunWebUI.
8+
9+
YunWebUI is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program; if not, write to the Free Software
21+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
23+
As a special exception, you may use this file as part of a free software
24+
library without restriction. Specifically, if other files instantiate
25+
templates or use macros or inline functions from this file, or you compile
26+
this file and link it with other files to produce an executable, this
27+
file does not by itself cause the resulting executable to be covered by
28+
the GNU General Public License. This exception does not however
29+
invalidate any other reasons why the executable file might be covered by
30+
the GNU General Public License.
31+
32+
Copyright 2013 Arduino LLC (http://www.arduino.cc/)
33+
-->
34+
<html xmlns="http://www.w3.org/1999/xhtml">
35+
<head>
36+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
37+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
38+
<link rel="stylesheet" type="text/css" href="<%= resource %>/arduino/style.ugly.css"/>
39+
<title>Y&uacute;n &#20113;</title>
40+
</head>
41+
<body>
42+
<div id="container">
43+
<div id="header">
44+
<div class="wrapper">
45+
<h1>Y&uacute;n &#20113;</h1>
46+
47+
<div id="logo"><a href="<%= pcdata(controller .. '/webpanel') %>"><img src="<%= resource %>/arduino/logo.png" alt="Y&uacute;n"/></a></div>
48+
<div id="logophone"><a href="<%= pcdata(controller .. '/webpanel') %>"><img src="<%= resource %>/arduino/logo_phone.png" alt="Y&uacute;n"/></a></div>
49+
</div>
50+
</div>
51+
<div id="content">
52+
<div class="wrapper divide">
53+
<h2>Uploading sketch...</h2>
54+
</div>
55+
<div class="wrapper divide">
56+
<% if string.len(merge_output) > 0 then %>
57+
<p>Error while merging sketch with bootloader</p>
58+
<textarea rows="5" readonly="readonly"><%= merge_output %></textarea>
59+
<% else %>
60+
<p>Merged sketch with bootloader.</p>
61+
<% end %>
62+
63+
<% if string.len(kill_bridge_output) > 0 then %>
64+
<p>Error while killing bridge</p>
65+
<textarea rows="5" readonly="readonly"><%= kill_bridge_output %></textarea>
66+
<% else %>
67+
<p>Previously running Bridge terminated.</p>
68+
<% end %>
69+
70+
<% if string.len(run_avrdude_output) > 0 then %>
71+
<p>Error while running avrdude</p>
72+
<textarea rows="5" readonly="readonly"><%= run_avrdude_output %></textarea>
73+
<% else %>
74+
<p>Sketch uploaded succesfully.</p>
75+
<% end %>
76+
</div>
77+
<div class="wrapper divide">
78+
<form method="get" action="<%= pcdata(controller .. '/webpanel') %>">
79+
<ul>
80+
<li>
81+
<div class="input_container">
82+
<input class="btTxt submit saveForm" type="submit" name="button" value="Back to the homepage">
83+
</div>
84+
</li>
85+
</ul>
86+
</form>
87+
</div>
88+
</div>
89+
</div>
90+
</body>
91+
</html>

0 commit comments

Comments
 (0)