Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify multi value properties sketch #65

Merged
merged 5 commits into from May 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Expand Up @@ -57,8 +57,8 @@ before_install:
- arduino --install-library RTCZero
- arduino --install-library WiFi101
- arduino --install-library WiFiNINA
- buildExampleSketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/$1/$1.ino; }
- buildExampleUtilitySketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/utility/$1/$1.ino; }
- buildExampleSketch() { arduino --verify --board $BOARD $PWD/examples/$1/$1.ino; }
- buildExampleUtilitySketch() { arduino --verify --board $BOARD $PWD/examples/utility/$1/$1.ino; }
install:
- mkdir -p $HOME/Arduino/libraries
- ln -s $PWD $HOME/Arduino/libraries/.
Expand All @@ -67,7 +67,9 @@ script:
- buildExampleSketch ArduinoIoTCloud_Travis_CI
- |
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ];
then buildExampleSketch WiFi_Cloud_Blink;
then
buildExampleSketch WiFi_Cloud_Blink;
buildExampleSketch MultiValue_example;
fi
- |
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ];
Expand Down
26 changes: 13 additions & 13 deletions examples/MultiValue_example/MultiValue_example.ino
Expand Up @@ -7,7 +7,7 @@

The following variables are automatically generated and updated when changes are made to the Thing properties

bool Switch;
bool switchButton;

Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
Expand All @@ -26,7 +26,7 @@ void setup() {
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection, "mqtts-sa.iot.oniudra.cc");
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
Expand All @@ -49,29 +49,29 @@ void loop() {
ArduinoCloud.update();
// Your code here

Switch = !Switch;
if (Switch) {
Loc = { .lat = latMov, .lon = lonMov };
Color = { .hue = hueRed, .sat = satRed, .bri = briRed };
switchButton = !switchButton;
if (switchButton) {
location = Location(latMov, lonMov);
color = Color(hueRed, satRed, briRed);
} else {
Loc = { .lat = latArd, .lon = lonArd };
Color = { .hue = hueGreen, .sat = satGreen, .bri = briGreen };
location = Location(latArd, lonArd);
color = Color(hueGreen, satGreen, briGreen);
}
delay(5000);
}


void onSwitchChange() {
void onSwitchButtonChange() {
// Do something
digitalWrite(LED_BUILTIN, Switch);
digitalWrite(LED_BUILTIN, switchButton);
}

void onColorChange() {
// Do something
Serial.print("Hue = ");
Serial.println(Color.getValue().hue);
Serial.println(color.getValue().hue);
Serial.print("Sat = ");
Serial.println(Color.getValue().sat);
Serial.println(color.getValue().sat);
Serial.print("Bri = ");
Serial.println(Color.getValue().bri);
Serial.println(color.getValue().bri);
}
14 changes: 7 additions & 7 deletions examples/MultiValue_example/thingProperties.h
Expand Up @@ -7,18 +7,18 @@ const char THING_ID[] = "";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)

void onSwitchChange();
void onSwitchButtonChange();
void onColorChange();

bool Switch;
CloudLocation Loc;
CloudColor Color;
bool switchButton;
CloudLocation location;
CloudColor color;

void initProperties() {
ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(Switch, READWRITE, ON_CHANGE, onSwitchChange);
ArduinoCloud.addProperty(Loc, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(Color, READWRITE, ON_CHANGE, onColorChange);
ArduinoCloud.addProperty(switchButton, READWRITE, ON_CHANGE, onSwitchButtonChange);
ArduinoCloud.addProperty(location, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
}

ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SSID, PASS);