Hi folks,
today I tried to get my MKR1000 to show the temperature information from the DHT11 in the Arduino app on Android.
The code I have working so far is to let the MKR1000 connect to my WiFi and let the sensor information show up in the serial monitor.
When trying to add Arduino Cloud components in the sketch, the code executes and after 2 reads from the sensor it restarts again and this goes in a loop.
The end result I would like to have is to view the sensor information on Android app. Any suggestions on how to do that?
Thank you for your time.
This is my code so far:
#include <SPI.h>
#include <WiFi101.h>
#include "thingProperties.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
#include "DHT.h"
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
dht.begin();
// ------------------->>>>>>>>>>>>>>> I ADDED THESE 2 LINES <<<<<<<<<<<-------------------------
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.println("You're connected to the network");
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
delay(2000);
}```