Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
5 changes: 1 addition & 4 deletions .github/workflows/release-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
# The project's folder on Arduino's download server for uploading builds
AWS_PLUGIN_TARGET: TODO
ARTIFACT_NAME: dist
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project
PROVISIONING_BINARIES_FOLDER: binaries

on:
push:
Expand Down Expand Up @@ -104,15 +102,14 @@ jobs:
# This step performs the following:
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt file
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project ({{.PROVISIONING_BINARIES_FOLDER}})
run: |
# GitHub's upload/download-artifact@v2 actions don't preserve file permissions,
# so we need to add execution permission back until the action is made to do this.
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
TAG="${GITHUB_REF/refs\/tags\//}"
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
-C ../../ ${{ env.PROVISIONING_BINARIES_FOLDER }} LICENSE.txt
-C ../../ LICENSE.txt
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
perl \
-pi \
Expand Down
17 changes: 8 additions & 9 deletions DistTasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ tasks:
Windows_32bit:
desc: Builds Windows 32 bit binaries
dir: "{{.DIST_DIR}}"
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project
cmds:
- |
docker run -v `pwd`/..:/home/build -w /home/build \
Expand All @@ -50,7 +49,7 @@ tasks:

cp {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../
cd ..
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe LICENSE.txt
cd {{.DIST_DIR}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

Expand All @@ -75,7 +74,7 @@ tasks:

cp {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../
cd ..
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe LICENSE.txt
cd {{.DIST_DIR}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

Expand All @@ -98,7 +97,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand All @@ -120,7 +119,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand All @@ -142,7 +141,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand All @@ -164,7 +163,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand Down Expand Up @@ -214,7 +213,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand All @@ -236,7 +235,7 @@ tasks:
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"

tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}

vars:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ This code is licensed under the terms of the GNU Affero General Public License v

### Requirements

This is all you need to use arduino-cloud-cli for device **provisioning**:
This is all you need to use arduino-cloud-cli:
* A client ID and a secret ID, retrievable from the [cloud](https://create.arduino.cc/iot/integrations) by creating a new API key
* The folder containing the precompiled provisioning firmwares (`binaries`) needs to be in the same location you run the command from

### Additional info

Expand Down
Binary file removed binaries/arduino.mbed_nano.nanorp2040connect.elf
Binary file not shown.
Binary file removed binaries/arduino.mbed_portenta.envie_m7.bin
Binary file not shown.
Binary file removed binaries/arduino.samd.mkr1000.bin
Binary file not shown.
Binary file removed binaries/arduino.samd.mkrgsm1400.bin
Binary file not shown.
Binary file removed binaries/arduino.samd.mkrnb1500.bin
Binary file not shown.
Binary file removed binaries/arduino.samd.mkrwifi1010.bin
Binary file not shown.
Binary file removed binaries/arduino.samd.nano_33_iot.bin
Binary file not shown.
Binary file removed binaries/getdeveui.arduino.samd.mkrwan1300.bin
Binary file not shown.
Binary file removed binaries/getdeveui.arduino.samd.mkrwan1310.bin
Binary file not shown.
124 changes: 124 additions & 0 deletions command/device/board.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// This file is part of arduino-cloud-cli.
//
// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package device

import (
"strings"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

var (
cryptoFQBN = []string{
"arduino:samd:nano_33_iot",
"arduino:samd:mkrwifi1010",
"arduino:mbed_nano:nanorp2040connect",
"arduino:mbed_portenta:envie_m7",
"arduino:samd:mkr1000",
"arduino:samd:mkrgsm1400",
"arduino:samd:mkrnb1500",
}
loraFQBN = []string{
"arduino:samd:mkrwan1310",
"arduino:samd:mkrwan1300",
}
)

// board contains details of a physical arduino board
type board struct {
fqbn string
serial string
dType string
port string
}

// isCrypto checks if the board is a valid arduino board with a
// supported crypto-chip
func (b *board) isCrypto() bool {
for _, f := range cryptoFQBN {
if b.fqbn == f {
return true
}
}
return false
}

// isCrypto checks if the board is a valid LoRa arduino board
func (b *board) isLora() bool {
for _, f := range loraFQBN {
if b.fqbn == f {
return true
}
}
return false
}

// boardFromPorts returns a board that matches all the criteria
// passed in. If no criteria are passed, it returns the first board found.
func boardFromPorts(ports []*rpc.DetectedPort, params *CreateParams) *board {
for _, port := range ports {
if portFilter(port, params) {
continue
}
boardFound := boardFilter(port.Boards, params)
if boardFound != nil {
b := &board{
fqbn: boardFound.Fqbn,
serial: port.SerialNumber,
dType: strings.Split(boardFound.Fqbn, ":")[2],
port: port.Address,
}
return b
}
}

return nil
}

// portFilter filters out the given port in the following cases:
// - if the port parameter does not match the actual port address.
// - if the the detected port does not contain any board.
// It returns:
// true -> to skip the port
// false -> to keep the port
func portFilter(port *rpc.DetectedPort, params *CreateParams) bool {
if len(port.Boards) == 0 {
return true
}
if params.Port != nil && *params.Port != port.Address {
return true
}
return false
}

// boardFilter looks for a board which has the same fqbn passed as parameter.
// If fqbn parameter is nil, then the first board found is returned.
// It returns:
// - a board if it is found.
// - nil if no board matching the fqbn parameter is found.
func boardFilter(boards []*rpc.BoardListItem, params *CreateParams) (board *rpc.BoardListItem) {
if params.Fqbn == nil {
return boards[0]
}
for _, b := range boards {
if b.Fqbn == *params.Fqbn {
return b
}
}
return
}
File renamed without changes.
70 changes: 10 additions & 60 deletions command/device/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ package device
import (
"errors"
"fmt"
"strings"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cloud-cli/arduino/cli"
"github.com/arduino/arduino-cloud-cli/internal/config"
"github.com/arduino/arduino-cloud-cli/internal/iot"
Expand All @@ -37,13 +35,6 @@ type CreateParams struct {
Fqbn *string // Board FQBN - Optional - If omitted then the first device found gets selected
}

type board struct {
fqbn string
serial string
dType string
port string
}

// Create command is used to provision a new arduino device
// and to add it to Arduino IoT Cloud.
func Create(params *CreateParams) (*DeviceInfo, error) {
Expand All @@ -62,6 +53,16 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
return nil, err
}

if !board.isCrypto() {
return nil, fmt.Errorf(
"board with fqbn %s found at port %s is not a device with a supported crypto-chip.\n"+
"Try the 'create-lora' command instead if it's a LoRa device"+
" or 'create-generic' otherwise",
board.fqbn,
board.port,
)
}

conf, err := config.Retrieve()
if err != nil {
return nil, err
Expand Down Expand Up @@ -104,54 +105,3 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
}
return devInfo, nil
}

// boardFromPorts returns a board that matches all the criteria
// passed in. If no criteria are passed, it returns the first board found.
func boardFromPorts(ports []*rpc.DetectedPort, params *CreateParams) *board {
for _, port := range ports {
if portFilter(port, params) {
continue
}
boardFound := boardFilter(port.Boards, params)
if boardFound != nil {
t := strings.Split(boardFound.Fqbn, ":")[2]
b := &board{boardFound.Fqbn, port.SerialNumber, t, port.Address}
return b
}
}

return nil
}

// portFilter filters out the given port in the following cases:
// - if the port parameter does not match the actual port address.
// - if the the detected port does not contain any board.
// It returns:
// true -> to skip the port
// false -> to keep the port
func portFilter(port *rpc.DetectedPort, params *CreateParams) bool {
if len(port.Boards) == 0 {
return true
}
if params.Port != nil && *params.Port != port.Address {
return true
}
return false
}

// boardFilter looks for a board which has the same fqbn passed as parameter.
// If fqbn parameter is nil, then the first board found is returned.
// It returns:
// - a board if it is found.
// - nil if no board matching the fqbn parameter is found.
func boardFilter(boards []*rpc.BoardListItem, params *CreateParams) (board *rpc.BoardListItem) {
if params.Fqbn == nil {
return boards[0]
}
for _, b := range boards {
if b.Fqbn == *params.Fqbn {
return b
}
}
return
}
Loading