Skip to content

Commit 51569a5

Browse files
Add test related to the changes
1 parent e0b89b0 commit 51569a5

File tree

439 files changed

+121802
-1
lines changed

Some content is hidden

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

439 files changed

+121802
-1
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
/arduino/security/testdata/
99
/.licenses/
1010
/site/
11-
/installer/
11+
/installer/
12+
/internal/integrationtest/testdata/

internal/integrationtest/compile_3/compile_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,40 @@ func TestCompilerErrOutput(t *testing.T) {
116116
compilerErr := requirejson.Parse(t, out).Query(".compiler_err")
117117
compilerErr.MustContain(`"error"`)
118118
}
119+
120+
func TestCompileRelativeLibraryPath(t *testing.T) {
121+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
122+
defer env.CleanUp()
123+
124+
_, _, err := cli.Run("core", "install", "arduino:samd")
125+
require.NoError(t, err)
126+
127+
// Install library and its dependencies
128+
_, _, err = cli.Run("lib", "install", "ArduinoIoTCloud")
129+
require.NoError(t, err)
130+
131+
// Uninstall library
132+
_, _, err = cli.Run("lib", "uninstall", "[email protected]")
133+
require.NoError(t, err)
134+
135+
// Copy the library as it was downloaded from the Github page and
136+
// move into one of the example's directories
137+
ArduinoIoTCloud := cli.WorkingDir().Join("ArduinoIoTCloud")
138+
err = paths.New("..", "testdata", "ArduinoIoTCloud-1.11.0").CopyDirTo(ArduinoIoTCloud)
139+
require.NoError(t, err)
140+
cli.SetWorkingDir(ArduinoIoTCloud.Join("examples", "ArduinoIoTCloud-Basic"))
141+
142+
// Compile using a relative path to the library
143+
_, _, err = cli.Run("compile", "-b", "arduino:samd:nano_33_iot", "--library", "../../")
144+
require.NoError(t, err)
145+
146+
// Install the same library using lib install and compile again using the relative path.
147+
// The manually installed library should be chosen
148+
_, _, err = cli.Run("lib", "install", "ArduinoIoTCloud")
149+
require.NoError(t, err)
150+
stdout, _, err := cli.Run("compile", "-b", "arduino:samd:nano_33_iot", "--library", "../../", "-v")
151+
require.NoError(t, err)
152+
require.Contains(t, string(stdout), "Multiple libraries were found for \"ArduinoIoTCloud.h\"")
153+
require.Contains(t, string(stdout), "Used: "+ArduinoIoTCloud.String())
154+
require.Contains(t, string(stdout), "Not used: "+cli.SketchbookDir().Join("libraries", "ArduinoIoTCloud").String())
155+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates.
3+
4+
IMPORTANT:
5+
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
6+
On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
7+
only after a value is sent to Cloud.
8+
9+
The full list of compatible boards can be found here:
10+
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
11+
*/
12+
13+
#include "arduino_secrets.h"
14+
#include "thingProperties.h"
15+
16+
void setup() {
17+
/* Initialize serial and wait up to 5 seconds for port to open */
18+
Serial.begin(9600);
19+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
20+
21+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
22+
initProperties();
23+
24+
/* Initialize Arduino IoT Cloud library */
25+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
26+
27+
setDebugMessageLevel(DBG_INFO);
28+
ArduinoCloud.printDebugInfo();
29+
}
30+
31+
float latMov = 45.5058224, lonMov = 9.1628673;
32+
float latArd = 45.0502078, lonArd = 7.6674765;
33+
34+
float hueRed = 0.0, satRed = 100.0, briRed = 100.0;
35+
float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0;
36+
37+
void loop() {
38+
ArduinoCloud.update();
39+
}
40+
41+
void onSwitchButtonChange() {
42+
if (switchButton)
43+
{
44+
location = Location(latMov, lonMov);
45+
color = Color(hueRed, satRed, briRed);
46+
}
47+
else
48+
{
49+
location = Location(latArd, lonArd);
50+
color = Color(hueGreen, satGreen, briGreen);
51+
}
52+
}
53+
54+
void onColorChange() {
55+
Serial.print("Hue = ");
56+
Serial.println(color.getValue().hue);
57+
Serial.print("Sat = ");
58+
Serial.println(color.getValue().sat);
59+
Serial.print("Bri = ");
60+
Serial.println(color.getValue().bri);
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <Arduino_ConnectionHandler.h>
3+
4+
/* A complete list of supported boards with WiFi is available here:
5+
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
6+
*/
7+
#if defined(BOARD_HAS_WIFI)
8+
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
9+
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
10+
#endif
11+
12+
/* ESP8266 ESP32*/
13+
#if defined(BOARD_ESP)
14+
#define SECRET_DEVICE_KEY "my-device-password"
15+
#endif
16+
17+
/* MKR GSM 1400 */
18+
#if defined(BOARD_HAS_GSM)
19+
#define SECRET_PIN ""
20+
#define SECRET_APN ""
21+
#define SECRET_LOGIN ""
22+
#define SECRET_PASS ""
23+
#endif
24+
25+
/* MKR WAN 1300/1310 */
26+
#if defined(BOARD_HAS_LORA)
27+
#define SECRET_APP_EUI ""
28+
#define SECRET_APP_KEY ""
29+
#endif
30+
31+
/* MKR NB 1500 */
32+
#if defined(BOARD_HAS_NB)
33+
#define SECRET_PIN ""
34+
#define SECRET_APN ""
35+
#define SECRET_LOGIN ""
36+
#define SECRET_PASS ""
37+
#endif
38+
39+
/* Portenta H7 + Ethernet shield */
40+
#if defined(BOARD_HAS_ETHERNET)
41+
#define SECRET_OPTIONAL_IP ""
42+
#define SECRET_OPTIONAL_DNS ""
43+
#define SECRET_OPTIONAL_GATEWAY ""
44+
#define SECRET_OPTIONAL_NETMASK ""
45+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if defined(BOARD_HAS_WIFI)
2+
#elif defined(BOARD_HAS_GSM)
3+
#elif defined(BOARD_HAS_LORA)
4+
#elif defined(BOARD_HAS_NB)
5+
#elif defined(BOARD_HAS_ETHERNET)
6+
#else
7+
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
8+
#endif
9+
10+
#if defined(BOARD_ESP)
11+
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
12+
#endif
13+
14+
void onSwitchButtonChange();
15+
void onColorChange();
16+
17+
bool switchButton;
18+
CloudLocation location;
19+
CloudColor color;
20+
21+
void initProperties() {
22+
#if defined(BOARD_ESP)
23+
ArduinoCloud.setBoardId(BOARD_ID);
24+
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
25+
#endif
26+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
27+
ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange);
28+
ArduinoCloud.addProperty(location, READ, ON_CHANGE);
29+
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
30+
#elif defined(BOARD_HAS_LORA)
31+
ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange);
32+
ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE);
33+
ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange);
34+
#endif
35+
}
36+
37+
#if defined(BOARD_HAS_WIFI)
38+
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
39+
#elif defined(BOARD_HAS_GSM)
40+
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
41+
#elif defined(BOARD_HAS_LORA)
42+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
43+
#elif defined(BOARD_HAS_NB)
44+
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
45+
#elif defined(BOARD_HAS_ETHERNET)
46+
/* DHCP mode */
47+
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
48+
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
49+
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
50+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud.
3+
4+
* Connect a potentiometer (or other analog sensor) to A0.
5+
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
6+
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
7+
8+
IMPORTANT:
9+
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
10+
On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
11+
only after a value is sent to Cloud.
12+
13+
The full list of compatible boards can be found here:
14+
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
15+
*/
16+
17+
#include "arduino_secrets.h"
18+
#include "thingProperties.h"
19+
20+
#if !defined(LED_BUILTIN)
21+
static int const LED_BUILTIN = 2;
22+
#endif
23+
24+
void setup() {
25+
/* Initialize serial and wait up to 5 seconds for port to open */
26+
Serial.begin(9600);
27+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
28+
29+
/* Configure LED pin as an output */
30+
pinMode(LED_BUILTIN, OUTPUT);
31+
32+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
33+
initProperties();
34+
35+
/* Initialize Arduino IoT Cloud library */
36+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
37+
38+
setDebugMessageLevel(DBG_INFO);
39+
ArduinoCloud.printDebugInfo();
40+
}
41+
42+
void loop() {
43+
ArduinoCloud.update();
44+
potentiometer = analogRead(A0);
45+
seconds = millis() / 1000;
46+
}
47+
48+
/*
49+
* 'onLedChange' is called when the "led" property of your Thing changes
50+
*/
51+
void onLedChange() {
52+
Serial.print("LED set to ");
53+
Serial.println(led);
54+
digitalWrite(LED_BUILTIN, led);
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <Arduino_ConnectionHandler.h>
3+
4+
/* A complete list of supported boards with WiFi is available here:
5+
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
6+
*/
7+
#if defined(BOARD_HAS_WIFI)
8+
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
9+
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
10+
#endif
11+
12+
/* ESP8266 ESP32*/
13+
#if defined(BOARD_ESP)
14+
#define SECRET_DEVICE_KEY "my-device-password"
15+
#endif
16+
17+
/* MKR GSM 1400 */
18+
#if defined(BOARD_HAS_GSM)
19+
#define SECRET_PIN ""
20+
#define SECRET_APN ""
21+
#define SECRET_LOGIN ""
22+
#define SECRET_PASS ""
23+
#endif
24+
25+
/* MKR WAN 1300/1310 */
26+
#if defined(BOARD_HAS_LORA)
27+
#define SECRET_APP_EUI ""
28+
#define SECRET_APP_KEY ""
29+
#endif
30+
31+
/* MKR NB 1500 */
32+
#if defined(BOARD_HAS_NB)
33+
#define SECRET_PIN ""
34+
#define SECRET_APN ""
35+
#define SECRET_LOGIN ""
36+
#define SECRET_PASS ""
37+
#endif
38+
39+
/* Portenta H7 + Ethernet shield */
40+
#if defined(BOARD_HAS_ETHERNET)
41+
#define SECRET_OPTIONAL_IP ""
42+
#define SECRET_OPTIONAL_DNS ""
43+
#define SECRET_OPTIONAL_GATEWAY ""
44+
#define SECRET_OPTIONAL_NETMASK ""
45+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#if defined(BOARD_HAS_WIFI)
2+
#elif defined(BOARD_HAS_GSM)
3+
#elif defined(BOARD_HAS_LORA)
4+
#elif defined(BOARD_HAS_NB)
5+
#elif defined(BOARD_HAS_ETHERNET)
6+
#else
7+
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
8+
#endif
9+
10+
#if defined(BOARD_ESP)
11+
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
12+
#endif
13+
14+
void onLedChange();
15+
16+
bool led;
17+
int potentiometer;
18+
int seconds;
19+
20+
void initProperties() {
21+
#if defined(BOARD_ESP)
22+
ArduinoCloud.setBoardId(BOARD_ID);
23+
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
24+
#endif
25+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET)
26+
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
27+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
28+
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
29+
#elif defined(BOARD_HAS_LORA)
30+
ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
31+
ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE);
32+
ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES);
33+
#endif
34+
}
35+
36+
#if defined(BOARD_HAS_ETHERNET)
37+
/* DHCP mode */
38+
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
39+
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
40+
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
41+
#elif defined(BOARD_HAS_WIFI)
42+
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
43+
#elif defined(BOARD_HAS_GSM)
44+
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
45+
#elif defined(BOARD_HAS_LORA)
46+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
47+
#elif defined(BOARD_HAS_NB)
48+
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
49+
#endif

0 commit comments

Comments
 (0)