Hey everybody,
I want to use the Iot Cloud messenger to change certain values in my code by writing a keyword like "interval". then i want to get a response message saying something like "Please enter new value" followed by another input by the user with the value.
My problem is, that the documentation for the messenger is close to not existant and im new to the whole arduino thing so most of the forum chats to this topic i dont understand fully or don't contribute to solving my problem.
If anyone has some insights on how to send messages back and forth while evaluating the user input I would greatly appreciate some help ![]()
I'll add some of my test code (which is probably going to be wrong on many levels ^^).
#include "thingProperties.h"
#include "DHT.h"
#define DHTTYPE DHT22
int dhtpin = 2;
bool outgoingMessage = false;
unsigned long previousMillis = 0;
const long interval = 2000; // Interval for sensor reading
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);
pinMode(2, INPUT);
// 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();
DHT dht(dhtpin, DHTTYPE);
dht.begin();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
float newTemp = dht.readTemperature();
float newHum = dht.readHumidity();
temp = newTemp;
hum = newHum;
heatIndex = dht.computeHeatIndex(temp, hum);
}
if (message1 == "test")
{
printMessageToDashboard("Test successfull!");
}
}
void printMessageToDashboard(String text)
{
outgoingMessage = true;
message = text;
}
void messageQueue(){
message5 = message4;
message4 = message3;
message3 = message2;
message2 = message1;
message1 = message;
Serial.println("M" + message);
Serial.println("M1" + message1);
Serial.println("M2" + message2);
Serial.println("M3" + message3);
Serial.println("M4" + message4);
Serial.println("M5" + message5);
}
void onSwitchChange() {
// Add your code here to act upon Switch change
if(_switch_){
dhtpin = 2;
}
else{
dhtpin = 3;
}
pinval = dhtpin;
}
void onMessageChange()
{
if (outgoingMessage)
{
outgoingMessage = false;
return;
}
messageQueue();
}