///////please enter your sensitive data in the Secret tab/arduino_secrets.h
charssid[]="cs";// your network SSID (name)
charpass[]="gkmrxuW6";// your network password (use for WPA, or use as key for WEP)
intkeyIndex=0;// your network key Index number (needed only for WEP)
intstatus=WL_IDLE_STATUS;
WiFiServerserver(80);
// ThingSpeak Settings
charthingSpeakAddress[]="api.thingspeak.com";
StringAPIKey="RFASZ7J7E3QY4M79";// enter your channel's Write API Key
constintupdateThingSpeakInterval=3*1000;// 20 second interval at which to update ThingSpeak
// Variable Setup
longlastConnectionTime=0;
booleanlastConnected=false;
// Initialize Arduino Ethernet Client
WiFiClientclient;
voidsetup(){
// put your setup code here, to run once:
ss.begin(9600);
Serial.begin(9600);
pinMode(6,OUTPUT);
while(!Serial){
;// wait for serial port to connect. Needed for Leonardo only
}
// 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 SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status=WiFi.begin(ssid,pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the status:
printWifiStatus();
}
voidprintWifiStatus(){
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddressip=WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the resensorPinceived signal strength:
longrssi=WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
charwaitForByte()
{
while(true){
charc=ss.read();
if(c!=-1){
returnc;
//while millis (give current time since booted up, then read when msg starts tehn check to see if run out of time then give up, read all 3 bytes potentially or else.
}
}
}
voidSensor(){
sensorValue=analogRead(sensorPin);// read the value from the sensor
Serial.println("got light value of:");
Serial.println(sensorValue);//prints the values coming from the sensor on the screen
//delay(100);
if(sensorValue>200&&sensorValue<250){
Serial.println("The light is starting to dim when being on");
}
if(sensorValue>150&&sensorValue<200){
Serial.println("The light is dim when being on");
}
if(sensorValue<150){
Serial.println("The light is too dim and needs changing soon");
}
if(sensorValue>=250){
Serial.println("The light is working great");
}
}
voidloop(){
// put your main code here, to run repeatedly:
Serial.println("looking for bluetooth message");
intx=waitForByte();
// Serial.println("got x");
// Serial.println(x);
inty=waitForByte();
// Serial.println(y);
intz=waitForByte();
// Serial.println(z);
// Serial.println("out of bt check");
// Serial.print("got ");
// Serial.print(x);
// Serial.print(" ");
// Serial.print(y);
// Serial.print(" ");
// Serial.println(z);
digitalWrite(6,y==64);
if(y==64)
{
Sensor();
}
sensorValue=analogRead(sensorPin);
StringsensorString=String(sensorValue);
// String sensorPin = String(analogRead(A0), DEC); // read light value