This is my code, I’m sure it’s very wrong as I’m not a coder but trying to learn. I can get the MKR1010 to connect to wifi but no sensor data is ever sent to Cayenne. Can anyone fix my errors?
-mark FYI the [ ] are showing up as squares for some reason
#include <SPI.h>
#include <CayenneMQTTMKR1010.h>
#include <WiFiNINA.h>
#include <DHT.h>
//Constants
#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
// --SENSOR–
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define TEMPERATURE_VIRTUAL_CHANNEL 1
#define HUMIDITY_VIRTUAL_CHANNEL 2
#define SECRET_SSID “"
#define SECRET_PASS "”
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.
// WiFi network info.
char ssid = SECRET_SSID;
char pass = SECRET_PASS;
int status = WL_IDLE_STATUS;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “";
char password[] = "”;
char clientID = “***”;
void setup() {
Serial.begin(9600);
//Cayenne.begin(username, password, clientID);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println(“Communication with WiFi module failed!”);
// 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 5 seconds for connection:
delay(5000);
}
// you’re connected now, so print out the data:
Serial.print(“You’re connected to the network”);
printCurrentNet();
printWifiData();
}
void loop()
{
Cayenne.loop();
Cayenne.begin(username, password, clientID);
}
// This function is called at intervals to send temperature sensor data to Cayenne in Celsius.
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), “temp”, “c”);
}
// This function is called at intervals to send humidity sensor data to Cayenne.
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), “rel_hum”, “p”);
}
void printWifiData() {
// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print(“IP Address: “);
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print(“MAC address: “);
Serial.print(mac[5], HEX);
Serial.print(”:”);
Serial.print(mac[4], HEX);
Serial.print(”:”);
Serial.print(mac[3], HEX);
Serial.print(“:”);
Serial.print(mac[2], HEX);
Serial.print(“:”);
Serial.print(mac[1], HEX);
Serial.print(“:”);
Serial.println(mac[0], HEX);
}
void printCurrentNet() {
// print the SSID of the network you’re attached to:
Serial.print(“SSID: “);
Serial.println(WiFi.SSID());
// print the MAC address of the router you’re attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print(“BSSID: “);
Serial.print(bssid[5], HEX);
Serial.print(”:”);
Serial.print(bssid[4], HEX);
Serial.print(”:”);
Serial.print(bssid[3], HEX);
Serial.print(“:”);
Serial.print(bssid[2], HEX);
Serial.print(“:”);
Serial.print(bssid[1], HEX);
Serial.print(“:”);
Serial.println(bssid[0], HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print(“Encryption Type:”);
Serial.println(encryption, HEX);
Serial.println();
}