Commit 82598276 authored by daniel.parker's avatar daniel.parker

Initial commit

parents
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>
#include "ThingSpeak.h"
#include <dht.h>
#define dht_pin A0
#define light_Pin A1
#define hydration_Pin A2
const unsigned long channel_id = 1276626;
const char write_api_key[] = "S0HMG0KSGUDVLH4T";
dht DHT;
WiFiUDP UDP;
WiFiClient client;
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS;
String hostName = "www.google.com";
int pingResult;
void setup() {
Serial.begin(9600);
while (!Serial) {
}
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("You're connected to the network");
printCurrentNet();
printWiFiData();
delay(500);
Serial.println("\n");
Serial.println("Daniel Parker\n");
Serial.println("Plant monitoring system\n\n");
delay(1000);
ThingSpeak.begin(client);
}
void loop() {
Serial.print("Pinging ");
Serial.print(hostName);
Serial.print(": ");
pingResult = WiFi.ping(hostName);
if (pingResult >= 0) {
Serial.print("SUCCESS! RTT = ");
Serial.print(pingResult);
Serial.println(" ms");
} else {
Serial.print("FAILED! Error code: ");
Serial.println(pingResult);
}
DHT.read11(dht_pin);
String lightVal;
lightVal=analogRead(light_Pin);
String hydrationVal;
hydrationVal=analogRead(hydration_Pin);
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print(" % ");
ThingSpeak.setField(3, String(DHT.humidity));
Serial.print("Temperature = ");
Serial.print(DHT.temperature);
Serial.print(" C ");
ThingSpeak.setField(2, String(DHT.temperature));
Serial.print("Ambient Light = ");
Serial.print(lightVal);
ThingSpeak.setField(1, String(lightVal));
Serial.print(" ");
Serial.print("Soil Hydration Level = ");
Serial.println(hydrationVal);
ThingSpeak.setField(4, String(hydrationVal));
ThingSpeak.writeFields(channel_id, write_api_key);
delay(300000);
//delay(60000); //(TEST VALUE)
//delay(15000); //(SECOND TEST VALUE)
}
void printWiFiData() {
IPAddress ip = WiFi.localIP();
Serial.print("IP address : ");
Serial.println(ip);
Serial.print("Subnet mask: ");
Serial.println((IPAddress)WiFi.subnetMask());
Serial.print("Gateway IP : ");
Serial.println((IPAddress)WiFi.gatewayIP());
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
Serial.println(rssi);
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
#define SECRET_SSID "VM2561973_EXT"
#define SECRET_PASS "ssGmvsvg3jjp"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment