Commit 9d020d3f authored by jake.beetham's avatar jake.beetham

Add new file

parents
//including necessary librarys
#include <ThreeWire.h>
#include <RtcDS1302.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include "ThingSpeak.h"
#include <Servo.h>
#include <Pushsafer.h>
//WiFi setup
char ssid[] = "VM9745152";
char pass[] = "4zpmvcNPtwbb";
int keyIndex = 0;
int WIFIstatus = WL_IDLE_STATUS;
//ThingSpeak Setup
const unsigned long channel_id = 2001759;
const char write_api_key[] = "5LQ7U666RIJW7AOX";
//Pushsafer Setup
#define PushsaferKey "O1cQuA8UPrYzEhxdPBxa"
//Servo Motor Setup
Servo myservo;
int pos = 180;
WiFiClient client;
Pushsafer pushsafer(PushsaferKey, client);
ThreeWire myWire(4,5,2);
RtcDS1302<ThreeWire> Rtc(myWire);
void setup() {
Serial.begin(9600);
//checking whether the wifi shield is present
if(WiFi.status() == WL_NO_SHIELD){
Serial.print("The WiFi shield is currently not present.");
while(true);
}
//checking whether a wifi connection has been secured
while (WIFIstatus != WL_CONNECTED){
Serial.print("Attempting to connect to ");
Serial.print(ssid);
Serial.println();
delay(30);
WIFIstatus = WiFi.begin(ssid, pass); //connecting to wifi using ssid and password
//wait 5 seconds for connection
delay(5000);
}
Serial.println("We have established a connection to your Wi-Fi!");
delay(15);
ThingSpeak.begin(client); //connect to ThingSpeak
myservo.attach(A0);
Rtc.Begin();
delay(30);
}
void loop() {
delay(1000);
RtcDateTime now = Rtc.GetDateTime();
delay(90);
checkDateTime(now);
delay(90);
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void checkDateTime(const RtcDateTime& dt){
char checkDateTime[20];
snprintf_P(checkDateTime,
countof(checkDateTime),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Day(),
dt.Month(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
if ((dt.Hour() == 9 && dt.Minute() == 30 && dt.Second() == 0) || (dt.Hour() == 13 && dt.Minute() == 30 && dt.Second() == 0) || (dt.Hour() == 17 && dt.Minute() == 30 && dt.Second() == 0)){
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
//apply delay here to release more food
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
Serial.println("Posting the your pets feeding data to ThingSpeak");
delay(60);
ThingSpeak.setField(1, "1");
delay(60);
ThingSpeak.writeFields(channel_id, write_api_key);
delay(250);
Serial.println("Your pet's feeding data has now been posted successfully!");
delay(60);
pushsafer.debug = true;
struct PushSaferInput input;
input.title = "Your pet has been fed!";
input.message = (checkDateTime);
input.icon = "1";
input.sound = "4";
input.vibration = "1";
input.device = "a";
input.url = "https://www.pushsafer.com/api";
input.urlTitle = "Open Pushsafer.com";
input.time2live = "60";
input.priority = "1";
input.retry = "";
input.expire = "";
input.answer = "";
Serial.println(pushsafer.sendEvent(input));
Serial.println("Notification Sent!");
delay(90);
}
}
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