It's been awhile and I have to re-educate myself on developing IoT stuff, so I started with baby steps.
The first code is very simple and runs fine. My dashboard is a switch and a messenger.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/95a72fb1-1b43-4f84-bba8-2cddc7e88cd6
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String test_msg;
bool test_switch;
Variables 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.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since TestSwitch is READ_WRITE variable, onTestSwitchChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestSwitchChange() {
// Add your code here to act upon TestSwitch change
if (test_switch) test_msg = "Switch On";
if (!test_switch) test_msg = "Switch Off";
}
/*
Since TestMsg is READ_WRITE variable, onTestMsgChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestMsgChange() {
// Add your code here to act upon TestMsg change
}
But as soon as I add the LCD unit, the IoT remote no longer updates. Anyone know why?
/*
AA :a simple code to check connection and LCD updates
The following variables are automatically generated and updated when changes are made to the Thing
String test_msg;
bool test_switch;
*/
#include "Wire.h"
#include "hd44780.h"
#include "hd44780ioClass/hd44780_I2Cexp.h"
#include "thingProperties.h"
//create LCD object
hd44780_I2Cexp lcd;
//LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// initialize LCD
int LCD_status;
LCD_status = lcd.begin(LCD_COLS, LCD_ROWS);
if (LCD_status) {hd44780::fatalError(LCD_status);}
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
//setup LCD
lcd.clear();
lcd.setCursor(1,2); //col,row
lcd.write("Ready...");
test_msg = "Ready.";
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since TestMsg is READ_WRITE variable, onTestMsgChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestMsgChange() {
// Add your code here to act upon TestMsg change
}
/*
Since TestSwitch is READ_WRITE variable, onTestSwitchChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestSwitchChange() {
// Add your code here to act upon TestSwitch change
lcd.setCursor(0,0);
if (test_switch) {
lcd.write("On ");
test_msg = "Switch On";
}
if (!test_switch) {
lcd.write("Off");
test_msg = "Switch Off";
}
}
Yes, I know my IF statements can be IF/ELSE. I was just doing some dirty code to test.
Thanks in advance.