Skip to content

Commit db3ef29

Browse files
authored
Merge branch 'devel' into proxy-setting
2 parents 29763f2 + 213356e commit db3ef29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6805
-62
lines changed

README.md

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,69 @@ arduino-create-agent
44
## Installation
55
Get the latest version of the Agent for all supported platforms:
66

7-
* [Windows](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-windows-installer.exe)
8-
* [MacOSX](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-osx-installer.dmg)
9-
* [Linux x64](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-linux-x64-installer.run)
7+
### Windows
8+
* [Windows with Edge](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-windows-installer-edge.exe)
9+
* [Windows with Chrome](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-windows-installer-chrome.exe)
10+
* [Windows with Firefox](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-windows-installer-firefox.exe)
11+
12+
### MacOSX
13+
* [MacOSX with Safari](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-osx-installer-safari.dmg)
14+
* [MacOSX with Chrome](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-osx-installer-chrome.dmg)
15+
* [MacOSX with Firefox](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-osx-installer-firefox.dmg)
16+
17+
### Linux
18+
* [Linux x64 with Chrome](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-linux-x64-installer-chrome.tar.gz)
19+
* [Linux x64 with Firefox](http://downloads.arduino.cc/CreateBridgeStable/ArduinoCreateAgent-1.1-linux-x64-installer-firefox.tar.gz)
1020

1121
arduino-create-agent is a fork of @johnlauer's serial-port-json-server (which we really want to thank for his kindness and great work)
1222

1323
The history has been rewritten to keep the repo small (thus removing all binaries committed in the past)
1424

25+
26+
27+
## Using multiple configurations
28+
29+
The agent support multiple configuration files. When multiple configurations are found by the agent, the tray icon menu is expanded to contain the different configurations:
30+
31+
![Agent multiple configuration tray icon](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/tray-icon-multiple-profiles.png)
32+
33+
The default `config.ini` file contains common configurations, every other config file inherit from it.
34+
35+
To create multiple configuration files:
36+
- stop the agent: tray bar icon -> pause then tray bar icon -> kill
37+
- find the `config.ini` file that is present in the `arduino-create-agent` installation folder
38+
- copy `config.ini` or create a new ini file (e.g. `example.ini`) with content:
39+
```ini
40+
name = your configuration name
41+
```
42+
add in this file other configuration options (you can override inherited values from `config.ini`)
43+
- restart the agent
44+
- click the tray bar icon and select the new configuration
45+
46+
**Tip**: you can also use the multiple configurations feature to create a new configuration with the proxy settings. This way you can have multiple proxies configured and disable proxy configuration with ease.
47+
48+
## When behind a proxy
49+
50+
The agent support working behind a proxy, but manual configuration is required ( there is no support for automatic proxy discovery ).
51+
52+
To add proxy configuration:
53+
- stop the agent: tray bar icon -> pause then tray bar icon -> kill
54+
- find the `config.ini` file that is present in the `arduino-create-agent` installation folder
55+
- copy `config.ini` to a new file (e.g. `proxy.ini`) with content:
56+
```ini
57+
name = Proxy Enabled
58+
[env]
59+
http_proxy=your.proxy.here
60+
https_proxy=your.https.proxyhere
61+
```
62+
- please note spaces are not allowed before and after the string `http_proxy`
63+
- restart the agent
64+
- select the proper Proxy profile as in the image
65+
- your agent will now work behind a proxy
66+
67+
![Agent multiple configuration tray icon](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/tray-icon-multiple-profiles.png)
68+
69+
1570
## Disable Autostart
1671

1772
### Windows
@@ -79,9 +134,20 @@ or in the location selected during the installation
79134
80135
Please use the current latest version:
81136
82-
* [Windows dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-windows-installer.exe)
83-
* [MacOSX dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-osx-installer.dmg)
84-
* [Linux x64 dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-linux-x64-installer.run)
137+
### Windows
138+
* [Windows with Edge dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-windows-installer-edge.exe)
139+
* [Windows with Chrome dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-windows-installer.exe)
140+
* [Windows with Firefox dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-windows-installer-firefox.exe)
141+
142+
### MacOSX
143+
* [MacOSX with Safari dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-osx-installer-safari.dmg)
144+
* [MacOSX with Chrome dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-osx-installer-chrome.dmg)
145+
* [MacOSX with Firefox dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-osx-installer-firefox.dmg)
146+
147+
### Linux
148+
* [Linux x64 with Chrome dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-linux-x64-installer-chrome.run)
149+
* [Linux x64 with Firefox dev](http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-linux-x64-installer-firefox.run)
150+
85151
86152
## How to use it
87153
The arduino create agent is a single binary that reads from a configuration file. Upon launching it will sit on the traybar and work in the background.
@@ -91,12 +157,12 @@ It will listen to http and websocket connections on a range of ports from `8990`
91157
### Discover the port
92158
You should make GET request to the `/info` endpoint on the possible ports, until you find a reply:
93159
94-
$ curl http://localhost:8990/info
95-
curl: (7) Failed to connect to localhost port 8990: Connection refused
96-
$ curl http://localhost:8991/info
160+
$ curl http://127.0.0.1:8990/info
161+
curl: (7) Failed to connect to 127.0.0.1 port 8990: Connection refused
162+
$ curl http://127.0.0.1:8991/info
97163
98-
$ curl http://localhost:8992/info
99-
{"http":"http://localhost:8992","https":"https://localhost:8991","version":"1.0.36","ws":"ws://localhost:8992","wss":"wss://localhost:8991"}
164+
$ curl http://127.0.0.1:8992/info
165+
{"http":"http://127.0.0.1:8992","https":"https://127.0.0.1:8991","version":"1.0.36","ws":"ws://127.0.0.1:8992","wss":"wss://127.0.0.1:8991"}
100166
101167
The reply will contain a json with info about the version and the http and https endpoints to use
102168
@@ -107,9 +173,9 @@ Once you have the websocket endpoint you need you can:
107173
```javascript
108174
var socket = io(endpoint);
109175
socket.on('connect', function () {
110-
socket.emit('message', yourCommand);
176+
socket.emit('command', yourCommand);
111177
112-
socket.on('message', function () {
178+
socket.on('command', function () {
113179
// Your code to handle messages
114180
})
115181
}
@@ -176,7 +242,7 @@ where you should replace /dev/ttyACM0 with the actual port and 9600 with the bau
176242
You will receive a message like:
177243

178244
```json
179-
{
245+
{
180246
"Cmd":"Open",
181247
"Desc":"Got register/open on port.",
182248
"Port":"/dev/ttyACM0",
@@ -189,7 +255,7 @@ You will receive a message like:
189255
or
190256

191257
```json
192-
{
258+
{
193259
"Cmd":"OpenFail",
194260
"Desc":"Error opening port. Serial port busy",
195261
"Port":"/dev/ttyACM0",
@@ -204,7 +270,7 @@ You can then close the port with
204270
You will receive a message like:
205271

206272
```json
207-
{
273+
{
208274
"Cmd":"Close",
209275
"Desc":"Got unregister/close on port.",
210276
"Port":"/dev/ttyACM0",
@@ -216,7 +282,7 @@ or
216282

217283

218284
```json
219-
{
285+
{
220286
"Error":"We could not find the serial port /dev/ttyACM0 that you were trying to close."
221287
}
222288
```
@@ -238,7 +304,7 @@ with a reply like
238304
You can receive output from the serial port by listening to messages like this:
239305

240306
```json
241-
{
307+
{
242308
"D":"output string\r\n"
243309
}
244310
```
@@ -309,17 +375,20 @@ The results of the upload will be delivered via websocket with messages that loo
309375

310376
## Development
311377

312-
From the project root dir executing:
378+
To clone the repository, run the following command:
313379
```
314-
export GOPATH=$PWD
315-
go get
316-
go build
380+
go get github.com/arduino/arduino-create-agent
317381
```
318-
will build the `arduino-create-agent` binary.
319382

320-
`compile_webidebridge.sh` contains the cross-platform script we use to deploy the agent for all the supported platforms; it needs to be adjusted as per your `go` installation paths and OS.
383+
This will clone the repository into your [Go workspace](https://golang.org/doc/code.html#Workspaces) or create a new workspace, if one doesn't exist. You can set `$GOPATH` to define where your Go workspace is located.
384+
385+
Now you can go to the project directory and compile it:
386+
```
387+
cd $GOPATH/src/github.com/arduino/arduino-create-agent
388+
go build
389+
```
321390

322-
You can use `bootstrapPlatforms` function to compile the needed CGO-enabled environment
391+
This will create the `arduino-create-agent` binary.
323392

324393
Other prerequisites are:
325394
* libappindicator (Linux only on Ubuntu `sudo apt-get install libappindicator1`)

certificates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
104104
Subject: pkix.Name{
105105
Organization: []string{"Arduino LLC US"},
106106
Country: []string{"US"},
107-
CommonName: "localhost",
107+
CommonName: "127.0.0.1",
108108
OrganizationalUnit: []string{"IT"},
109109
},
110110
NotBefore: notBefore,

config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ v = true # show debug logging
77
appName = CreateBridge
88
updateUrl = http://downloads.arduino.cc/
99
#updateUrl = http://localhost/
10-
origins = http://webide.arduino.cc:8080
10+
origins = http://local.arduino.cc:8080
1111
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests

conn.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"io/ioutil"
1717
"net/http"
18+
"os"
1819
"path/filepath"
1920

2021
log "github.com/Sirupsen/logrus"
@@ -76,7 +77,7 @@ func uploadHandler(c *gin.Context) {
7677
data := new(Upload)
7778
c.BindJSON(data)
7879

79-
log.Printf("%+v", data)
80+
log.Printf("%+v %+v %+v %+v %+v %+v", data.Port, data.Board, data.Rewrite, data.Commandline, data.Extra, data.Filename)
8081

8182
if data.Port == "" {
8283
c.String(http.StatusBadRequest, "port is required")
@@ -119,13 +120,27 @@ func uploadHandler(c *gin.Context) {
119120
var filePaths []string
120121
filePaths = append(filePaths, filePath)
121122

123+
tmpdir, err := ioutil.TempDir("", "extrafiles")
124+
if err != nil {
125+
c.String(http.StatusBadRequest, err.Error())
126+
return
127+
}
128+
122129
for _, extraFile := range data.ExtraFiles {
123-
path := filepath.Join(filepath.Dir(filePath), extraFile.Filename)
130+
path := filepath.Join(tmpdir, extraFile.Filename)
124131
filePaths = append(filePaths, path)
125132
log.Printf("Saving %s on %s", extraFile.Filename, path)
133+
134+
err = os.MkdirAll(filepath.Dir(path), 0744)
135+
if err != nil {
136+
c.String(http.StatusBadRequest, err.Error())
137+
return
138+
}
139+
126140
err := ioutil.WriteFile(path, extraFile.Hex, 0644)
127141
if err != nil {
128-
log.Printf(err.Error())
142+
c.String(http.StatusBadRequest, err.Error())
143+
return
129144
}
130145
}
131146

@@ -135,7 +150,7 @@ func uploadHandler(c *gin.Context) {
135150

136151
go func() {
137152
// Resolve commandline
138-
commandline, err := upload.PartiallyResolve(data.Board, filePath, data.Commandline, data.Extra, &Tools)
153+
commandline, err := upload.PartiallyResolve(data.Board, filePath, tmpdir, data.Commandline, data.Extra, &Tools)
139154
if err != nil {
140155
send(map[string]string{uploadStatusStr: "Error", "Msg": err.Error()})
141156
return
9.87 KB
Loading

info.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package main
22

33
import (
4+
"strings"
5+
46
"github.com/gin-gonic/gin"
57
"go.bug.st/serial.v1"
68
)
79

810
func infoHandler(c *gin.Context) {
11+
host := c.Request.Host
12+
parts := strings.Split(host, ":")
13+
host = parts[0]
14+
915
c.JSON(200, gin.H{
1016
"version": version,
11-
"http": "http://localhost" + port,
17+
"http": "http://" + host + port,
1218
"https": "https://localhost" + portSSL,
13-
"ws": "ws://localhost" + port,
19+
"ws": "ws://" + host + port,
1420
"wss": "wss://localhost" + portSSL,
21+
"origins": origins,
22+
"update_url": updateUrl,
1523
})
1624
}
1725

main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"runtime/debug"
1313
"strconv"
14+
"strings"
1415
"text/template"
1516
"time"
1617

@@ -220,14 +221,20 @@ func main() {
220221

221222
socketHandler := wsHandler().ServeHTTP
222223

223-
extraOriginStr := "https://create.arduino.cc, http://create.arduino.cc, https://create-dev.arduino.cc, http://create-dev.arduino.cc, https://create-intel.arduino.cc, http://create-intel.arduino.cc"
224+
extraOrigins := []string{
225+
"https://create.arduino.cc",
226+
"http://create.arduino.cc", "https://create-dev.arduino.cc", "http://create-dev.arduino.cc", "https://create-intel.arduino.cc", "http://create-intel.arduino.cc",
227+
}
224228

225229
for i := 8990; i < 9001; i++ {
226-
extraOriginStr = extraOriginStr + ", http://localhost:" + strconv.Itoa(i) + ", https://localhost:" + strconv.Itoa(i)
230+
port := strconv.Itoa(i)
231+
extraOrigins = append(extraOrigins, "http://localhost:"+port)
232+
extraOrigins = append(extraOrigins, "https://localhost:"+port)
233+
extraOrigins = append(extraOrigins, "http://127.0.0.1:"+port)
227234
}
228235

229236
r.Use(cors.Middleware(cors.Config{
230-
Origins: *origins + ", " + extraOriginStr,
237+
Origins: *origins + ", " + strings.Join(extraOrigins, ", "),
231238
Methods: "GET, PUT, POST, DELETE",
232239
RequestHeaders: "Origin, Authorization, Content-Type",
233240
ExposedHeaders: "",

0 commit comments

Comments
 (0)