Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ arduino-connector
arduino-connector.cfg
arduino-connector-arm
.idea
setup_host_test_env.sh
32 changes: 4 additions & 28 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# need to use bash in order to use source command
SHELL := /bin/bash

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOTEST_TIMEOUT=20m
GOGET=$(GOCMD) get


.PHONY: all test clean

all: test build
Expand All @@ -22,7 +27,7 @@ integ-test:
$(GOBUILD) -ldflags "-X main.version=1.0.0-dev" github.com/arduino/arduino-connector
cd ./test && ./upload_dev_artifacts_on_s3.sh
cd ./test && vagrant provision
$(GOTEST) ./...
source ./test/setup_host_test_env.sh && $(GOTEST) ./... -timeout $(GOTEST_TIMEOUT)

teardown-test:
cd ./test && ./teardown_iot_device.sh
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

The Arduino Connector allows your device to connect to the Arduino Cloud, and push and receive messages through the [MQTT protocol](http://mqtt.org/). You can see and control all your cloud-enabled devices via a web app called [My Devices](https://create.arduino.cc/devices).

## Build Notes

Build for ARM devices

```bash
GOOS=linux GOARCH=arm go build -ldflags "-X main.version=arm-dev" -o=arduino-connector-arm github.com/arduino/arduino-connector
```


## Install

Follow the "Getting Started" guides to install the connector and allow your devices to communicate with the cloud via Arduino Create. You can install the connector onto a [Up2 board](https://create.arduino.cc/getting-started/up2) or a generic [Intel-based platform running Linux](https://create.arduino.cc/getting-started/intel-platforms).
Expand Down Expand Up @@ -721,10 +730,12 @@ chmod +x install.sh

## run integration tests with vagrant
please note that:
* the thing `devops-test:75b87fe3-169d-4603-a018-7fde9c667850`
* the thing `devops-test:c4d6adc7-a2ca-43ec-9ea6-20568bf407fc`
* the iot IAM policy `DevicePolicy`
* the arduino user `devops-test`
* the s3 bucket `arduino-tmp`
* the test sketch `sketch_devops_integ_test`
* the private image `private_image`
are resources that must be manually created in the Arduino Cloud environment, in order to replicate the testing, you will need to create those resources on your environment and edit the test setup/teardown scripts:
* `upload_dev_artifacts_on_s3.sh`
* `create_iot_device.sh`
Expand Down
41 changes: 22 additions & 19 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"syscall"
"time"

mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/eclipse/paho.mqtt.golang"
"github.com/kardianos/osext"
"github.com/kr/pty"
nats "github.com/nats-io/go-nats"
"github.com/nats-io/go-nats"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)
Expand Down Expand Up @@ -125,7 +125,7 @@ func (status *Status) UploadEvent(client mqtt.Client, msg mqtt.Message) {
return
}

sketchFolder, err := getSketchFolder()
sketchFolder, err := getSketchFolder(status)
sketchPath := filepath.Join(sketchFolder, sketch.Name)

if _, err = os.Stat(sketchPath); !os.IsNotExist(err) {
Expand All @@ -137,7 +137,7 @@ func (status *Status) UploadEvent(client mqtt.Client, msg mqtt.Message) {
}
}

folder, err := getSketchFolder()
folder, err := getSketchFolder(status)
if err != nil {
status.Error("/upload", errors.Wrapf(err, "create sketch folder %s", info.ID))
return
Expand All @@ -161,7 +161,7 @@ func (status *Status) UploadEvent(client mqtt.Client, msg mqtt.Message) {
sketch.ID = info.ID
sketch.Name = info.Name
// save ID-Name to a sort of DB
insertSketchInDB(sketch.Name, sketch.ID)
insertSketchInDB(sketch.Name, sketch.ID, status)

// spawn process
pid, _, _, err := spawnProcess(name, &sketch, status)
Expand All @@ -188,39 +188,42 @@ func (status *Status) UploadEvent(client mqtt.Client, msg mqtt.Message) {
// }(stdout)
}

func getSketchFolder() (string, error) {
func getSketchFolder(status *Status) (string, error) {
// create folder if it doesn't exist
folder, err := osext.ExecutableFolder()
if status.config.SketchesPath != "" {
folder = status.config.SketchesPath
}
folder = filepath.Join(folder, "sketches")
if _, err := os.Stat(folder); os.IsNotExist(err) {
err = os.Mkdir(folder, 0700)
}
return folder, err
}

func getSketchDBFolder() (string, error) {
func getSketchDBFolder(status *Status) (string, error) {
// create folder if it doesn't exist
folder, err := getSketchFolder()
folder, err := getSketchFolder(status)
folder = filepath.Join(folder, "db")
if _, err := os.Stat(folder); os.IsNotExist(err) {
err = os.Mkdir(folder, 0700)
}
return folder, err
}

func getSketchDB() (string, error) {
func getSketchDB(status *Status) (string, error) {
// create folder if it doesn't exist
folder, err := getSketchDBFolder()
folder, err := getSketchDBFolder(status)
if err != nil {
return "", err
}
db := filepath.Join(folder, "db")
return db, err
}

func insertSketchInDB(name string, id string) {
func insertSketchInDB(name string, id string, status *Status) {
// create folder if it doesn't exist
db, err := getSketchDB()
db, err := getSketchDB(status)
if err != nil {
return
}
Expand All @@ -239,9 +242,9 @@ func insertSketchInDB(name string, id string) {
ioutil.WriteFile(db, data, 0600)
}

func getSketchIDFromDB(name string) (string, error) {
func getSketchIDFromDB(name string, status *Status) (string, error) {
// create folder if it doesn't exist
db, err := getSketchDB()
db, err := getSketchDB(status)
if err != nil {
return "", errors.New("Can't open DB")
}
Expand Down Expand Up @@ -412,7 +415,7 @@ func (d *dylibMap) Contains(match string) bool {
return false
}

func downloadDylibDependencies(library string) error {
func downloadDylibDependencies(library string, status *Status) error {
resp, err := http.Get("https://downloads.arduino.cc/libArduino/dylib_dependencies.txt")
if err != nil {
return errors.New("Can't download dylibs registry")
Expand All @@ -431,7 +434,7 @@ func downloadDylibDependencies(library string) error {
}
for _, element := range v {
if element.Contains(library) {
folder, _ := getSketchFolder()
folder, _ := getSketchFolder(status)
fmt.Println(element.Help)
if element.Help != "" {
// TODO: remove and replace with a status.Info()
Expand Down Expand Up @@ -467,7 +470,7 @@ func checkForLibrariesMissingError(filepath string, sketch *SketchStatus, status
fmt.Println("Missing library!")
library := extractLibrary(err)
status.Info("/upload", "Downloading needed libraries")
if err := downloadDylibDependencies(library); err != nil {
if err := downloadDylibDependencies(library, status); err != nil {
status.Error("/upload", err)
}
status.Error("/upload", errors.New("Missing libraries, install them and relaunch the sketch"))
Expand Down Expand Up @@ -591,7 +594,7 @@ func applyAction(sketch *SketchStatus, action string, status *Status) error {
if sketch.PID != 0 {
err = process.Signal(syscall.SIGCONT)
} else {
folder, err := getSketchFolder()
folder, err := getSketchFolder(status)
if err != nil {
return err
}
Expand All @@ -618,7 +621,7 @@ func applyAction(sketch *SketchStatus, action string, status *Status) error {
case "DELETE":
applyAction(sketch, "STOP", status)
fmt.Println("delete called")
sketchFolder, err := getSketchFolder()
sketchFolder, err := getSketchFolder(status)
err = os.Remove(filepath.Join(sketchFolder, sketch.Name))
if err != nil {
fmt.Println("error deleting sketch")
Expand Down
Loading