@@ -116,29 +116,40 @@ <h1>Arduino Create Agent - Debug</h1>
116
116
</ div >
117
117
</ div >
118
118
</ div >
119
-
119
+ <!-- Upload -->
120
+ < div class ="container ">
121
+ < div class ="row ">
122
+ < div class ="col ">
123
+ < div class ="form-group ">
124
+ < label for ="upload-board "> Board</ label >
125
+ < input type ="text " class ="form-control " id ="upload-board " required value ="arduino:avr:uno ">
126
+ </ div >
127
+ </ div >
128
+ < div class ="col ">
129
+ < div class ="form-group ">
130
+ < label for ="upload-sketch "> Sketch</ label >
131
+ < input type ="text " class ="form-control " id ="upload-sketch " required value ="/tmp/sketch ">
132
+ </ div >
133
+ </ div >
134
+ </ div >
135
+ < div class ="row ">
136
+ < div class ="col ">
137
+ < p > < button class ="btn btn-primary " onclick ="upload() "> Upload</ button > </ p >
138
+ </ div >
139
+ </ div >
140
+ < div class ="row ">
141
+ < div class ="col ">
142
+ < div class ="form-group ">
143
+ < pre id ="upload-req "> </ pre >
144
+ </ div >
145
+ </ div >
146
+ < div class ="col ">
147
+ < pre id ="upload-code "> </ pre >
148
+ </ div >
149
+ </ div >
150
+ </ div >
120
151
121
152
< script >
122
- function discovery ( ) {
123
- var req = new Request ( '/v1/discover' , {
124
- method : 'GET'
125
- } ) ;
126
-
127
- var reqEl = document . getElementById ( 'discovery-req' ) ;
128
- reqEl . textContent = req . method + ' ' + req . url + '\n' ;
129
- reqEl . textContent = reqEl . textContent + '------------------------------------\n'
130
-
131
- fetch ( req ) . then ( function ( response ) {
132
- reqEl . textContent = reqEl . textContent + 'STATUS ' + response . status + '\n' ;
133
- reqEl . textContent = reqEl . textContent + '------------------------------------\n\n'
134
- return response . json ( ) ;
135
- } ) . then ( function ( response ) {
136
- var codeEl = document . getElementById ( 'discovery-code' ) ;
137
-
138
- codeEl . textContent = JSON . stringify ( response , null , 2 ) + '\n' ;
139
- } ) ;
140
- }
141
-
142
153
var ws ;
143
154
144
155
function connect ( ) {
@@ -154,7 +165,7 @@ <h1>Arduino Create Agent - Debug</h1>
154
165
}
155
166
156
167
codeEl . textContent = '' ;
157
- ws = new WebSocket ( "ws://localhost:9000 /v1/connect?port=" + port + "&baud=" + baud ) ;
168
+ ws = new WebSocket ( "ws://" + window . location . host + " /v1/connect?port=" + port + "&baud=" + baud ) ;
158
169
ws . onopen = function ( ) {
159
170
formEl . removeAttribute ( 'hidden' )
160
171
}
@@ -183,36 +194,28 @@ <h1>Arduino Create Agent - Debug</h1>
183
194
ws . send ( msg )
184
195
}
185
196
186
- function tools ( ) {
187
- var req = new Request ( '/v1/tools' , {
188
- method : 'GET'
189
- } ) ;
190
-
191
- var reqEl = document . getElementById ( 'tools-req' ) ;
192
- reqEl . textContent = req . method + ' ' + req . url + '\n' ;
193
- reqEl . textContent = reqEl . textContent + '------------------------------------\n'
194
-
195
- fetch ( req ) . then ( function ( response ) {
196
- reqEl . textContent = reqEl . textContent + 'STATUS ' + response . status + '\n' ;
197
- reqEl . textContent = reqEl . textContent + '------------------------------------\n\n'
198
- return response . json ( ) ;
199
- } ) . then ( function ( response ) {
200
- var codeEl = document . getElementById ( 'tools-code' ) ;
197
+ function discovery ( ) {
198
+ req ( 'GET' , '/v1/discover' , 'discovery' )
199
+ }
201
200
202
- codeEl . textContent = JSON . stringify ( response , null , 2 ) + '\n' ;
203
- } ) ;
201
+ function tools ( ) {
202
+ req ( 'GET' , '/v1/tools' , 'tools' ) ;
204
203
}
205
204
206
205
function install ( ) {
207
206
var packager = document . getElementById ( 'install-packager' ) . value ;
208
207
var name = document . getElementById ( 'install-name' ) . value ;
209
208
var version = document . getElementById ( 'install-version' ) . value ;
210
209
211
- var req = new Request ( '/v1/tools/' + packager + '/' + name + '/' + version , {
212
- method : 'POST'
210
+ req ( 'POST' , '/v1/tools/' + packager + '/' + name + '/' + version , 'install' ) ;
211
+ }
212
+
213
+ function req ( method , url , el ) {
214
+ var req = new Request ( url , {
215
+ method : method
213
216
} ) ;
214
217
215
- var reqEl = document . getElementById ( 'install -req') ;
218
+ var reqEl = document . getElementById ( el + ' -req') ;
216
219
reqEl . textContent = req . method + ' ' + req . url + '\n' ;
217
220
reqEl . textContent = reqEl . textContent + '------------------------------------\n'
218
221
@@ -221,11 +224,9 @@ <h1>Arduino Create Agent - Debug</h1>
221
224
reqEl . textContent = reqEl . textContent + '------------------------------------\n\n'
222
225
return response . json ( ) ;
223
226
} ) . then ( function ( response ) {
224
- var codeEl = document . getElementById ( 'install-code' ) ;
225
-
227
+ var codeEl = document . getElementById ( el + '-code' ) ;
226
228
codeEl . textContent = JSON . stringify ( response , null , 2 ) + '\n' ;
227
229
} ) ;
228
230
}
229
-
230
231
</ script >
231
232
</ body >
0 commit comments