/* | |
This library is free software; you can redistribute it and/or | |
modify it under the terms of the GNU Lesser General Public | |
License as published by the Free Software Foundation; either | |
version 2.1 of the License, or (at your option) any later version. | |
This library is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
Lesser General Public License for more details. | |
You should have received a copy of the GNU Lesser General Public | |
License along with this library; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
#include <Wire.h> | |
#include <SPI.h> | |
#include <WiFi.h> | |
#include "Adafruit_SI1145.h" | |
#include "rgb_lcd.h" | |
rgb_lcd lcd; | |
const int colorR = 255; | |
const int colorG = 0; | |
const int colorB = 0; | |
const int ON = 1; | |
const int OFF = 0; | |
char ssid[] = "C3-G"; // your network SSID (name) | |
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) | |
int keyIndex = 0; // your network key Index number (needed only for WEP) | |
int status = WL_IDLE_STATUS; | |
// if you don't want to use DNS (and reduce your sketch size) | |
// use the numeric IP instead of the name for the server: | |
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) | |
char server[] = "uv-smart-boston123.appspot.com"; // name address for Google (using DNS) | |
// constants won't change. They're used here to | |
// set pin numbers: | |
const int buttonPin = 2; // the number of the pushbutton pin | |
// variables will change: | |
int buttonState = 0; // variable for reading the pushbutton status | |
int stat = OFF; | |
WiFiClient client; | |
Adafruit_SI1145 uv = Adafruit_SI1145(); | |
void setup() | |
{ | |
// initialize the pushbutton pin as an input: | |
pinMode(buttonPin, INPUT); | |
turnLCDOff(); | |
setupWifi(); | |
setupUVSensor(); | |
} | |
void loop() | |
{ | |
// set the cursor to column 0, line 1 | |
// (note: line 1 is the second row, since counting begins with 0): | |
lcd.setCursor(0, 0); | |
// read the state of the pushbutton value: | |
buttonState = digitalRead(buttonPin); | |
// check if the pushbutton is pressed. | |
if (buttonState == HIGH) { | |
if(stat==OFF){ | |
stat = ON; | |
turnLCDOn(); | |
printUV(); | |
}else{ | |
stat = OFF; | |
turnLCDOff(); | |
} | |
} | |
if(stat==ON){ | |
printUV(); | |
} | |
delay(500); | |
} | |
void turnLCDOff(){ | |
lcd.setRGB(0, 0, 0); | |
lcd.noDisplay(); | |
} | |
void turnLCDOn(){ | |
lcd.begin(16, 2); | |
lcd.setRGB(colorR, colorG, colorB); | |
} | |
void printToLCD(){ | |
// Print a message to the LCD. | |
lcd.print("hello, world!"); | |
} | |
String IpAddress2String(const IPAddress& ipAddress) | |
{ | |
return String(ipAddress[0]) + String(".") +\ | |
String(ipAddress[1]) + String(".") +\ | |
String(ipAddress[2]) + String(".") +\ | |
String(ipAddress[3]) ; | |
} | |
void printWifiStatus() { | |
// print the SSID of the network you're attached to: | |
Serial.print("SSID: "); | |
Serial.println(WiFi.SSID()); | |
// print your WiFi shield's IP address: | |
IPAddress ip = WiFi.localIP(); | |
Serial.print("IP Address: "); | |
Serial.println(IpAddress2String(ip)); | |
// print the received signal strength: | |
long rssi = WiFi.RSSI(); | |
Serial.print("signal strength (RSSI):"); | |
Serial.print(rssi); | |
Serial.println(" dBm"); | |
} | |
void setupWifi(){ | |
//Initialize serial and wait for port to open: | |
Serial.begin(9600); | |
// check for the presence of the shield: | |
if (WiFi.status() == WL_NO_SHIELD) { | |
Serial.println("WiFi shield not present"); | |
// don't continue: | |
while (true); | |
} | |
String fv = WiFi.firmwareVersion(); | |
if (fv != "1.1.0") { | |
Serial.println("Please upgrade the firmware"); | |
} | |
// attempt to connect to Wifi network: | |
lcd.begin(16, 2); | |
while (status != WL_CONNECTED) { | |
lcd.setCursor(0,0); | |
lcd.write("Attempting.."); | |
delay(200); | |
Serial.print("Attempting to connect to SSID: "); | |
lcd.setCursor(0,1); | |
lcd.write(ssid); | |
delay(200); | |
Serial.println(ssid); | |
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | |
status = WiFi.begin(ssid); | |
// wait 10 seconds for connection: | |
delay(10000); | |
} | |
lcd.setCursor(0,0); | |
Serial.println("Connected to wifi"); | |
lcd.write("Connected!"); | |
printWifiStatus(); | |
} | |
void printUV(){ | |
//if(stat==ON){ | |
Serial.println("==================="); | |
Serial.print("Vis: "); Serial.println(uv.readVisible()); | |
Serial.print("IR: "); Serial.println(uv.readIR()); | |
int UVindex = uv.readUV(); | |
String UVindexString = String(UVindex); | |
if(UVindex<10){ | |
UVindexString = "00"+String(UVindex); | |
}else if(UVindex<100){ | |
UVindexString = "0"+String(UVindex); | |
} | |
Serial.print("UV (div100): ");Serial.println(UVindex); | |
String text = "UV (div100): "+ UVindexString; | |
printToLCD(text); | |
sendUVToApi(UVindex); | |
delay(5000); | |
//} | |
} | |
void setupUVSensor(){ | |
if (! uv.begin()) { | |
Serial.println("Didn't find Si1145"); | |
while (1); | |
} | |
} | |
void printToLCD(String& text){ | |
// Print a message to the LCD. | |
lcd.setCursor(0, 0); | |
lcd.print("UV Smart"); | |
lcd.setCursor(0, 1); | |
lcd.print(text); | |
} | |
void sendUVToApi(const int& UVindex){ | |
if (client.connect(server, 80)) { | |
IPAddress ip = WiFi.localIP(); | |
String getdata = "/uvapi?uv="+String(UVindex)+"&ir="+String(UVindex); | |
Serial.println("connected to server"); | |
// Make a HTTP request: | |
client.println("GET "+getdata+" HTTP/1.1"); | |
client.println("Host: "+String(server)); | |
client.println("Connection: close"); | |
client.println(); | |
Serial.println("/uvapi?uv="+String(UVindex)+"&ir="+IpAddress2String(ip)); | |
Serial.println("Sent! to "+String(server)); | |
Serial.println("disconnecting from server."); | |
client.stop(); | |
} | |
} | |
/********************************************************************************************************* | |
END FILE | |
*********************************************************************************************************/ |
/* | |
This library is free software; you can redistribute it and/or | |
modify it under the terms of the GNU Lesser General Public | |
License as published by the Free Software Foundation; either | |
version 2.1 of the License, or (at your option) any later version. | |
This library is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
Lesser General Public License for more details. | |
You should have received a copy of the GNU Lesser General Public | |
License along with this library; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
#include <Wire.h> | |
#include <SPI.h> | |
#include <WiFi.h> | |
#include "Adafruit_SI1145.h" | |
#include "rgb_lcd.h" | |
rgb_lcd lcd; | |
const int colorR = 255; | |
const int colorG = 0; | |
const int colorB = 0; | |
const int ON = 1; | |
const int OFF = 0; | |
char ssid[] = "C3-G"; // your network SSID (name) | |
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) | |
int keyIndex = 0; // your network key Index number (needed only for WEP) | |
int status = WL_IDLE_STATUS; | |
// if you don't want to use DNS (and reduce your sketch size) | |
// use the numeric IP instead of the name for the server: | |
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) | |
char server[] = "uv-smart-boston123.appspot.com"; // name address for Google (using DNS) | |
// constants won't change. They're used here to | |
// set pin numbers: | |
const int buttonPin = 2; // the number of the pushbutton pin | |
// variables will change: | |
int buttonState = 0; // variable for reading the pushbutton status | |
int stat = OFF; | |
WiFiClient client; | |
Adafruit_SI1145 uv = Adafruit_SI1145(); | |
void setup() | |
{ | |
// initialize the pushbutton pin as an input: | |
pinMode(buttonPin, INPUT); | |
turnLCDOff(); | |
setupWifi(); | |
setupUVSensor(); | |
} | |
void loop() | |
{ | |
// set the cursor to column 0, line 1 | |
// (note: line 1 is the second row, since counting begins with 0): | |
lcd.setCursor(0, 0); | |
// read the state of the pushbutton value: | |
buttonState = digitalRead(buttonPin); | |
// check if the pushbutton is pressed. | |
if (buttonState == HIGH) { | |
if(stat==OFF){ | |
stat = ON; | |
turnLCDOn(); | |
printUV(); | |
}else{ | |
stat = OFF; | |
turnLCDOff(); | |
} | |
} | |
if(stat==ON){ | |
printUV(); | |
} | |
delay(500); | |
} | |
void turnLCDOff(){ | |
lcd.setRGB(0, 0, 0); | |
lcd.noDisplay(); | |
} | |
void turnLCDOn(){ | |
lcd.begin(16, 2); | |
lcd.setRGB(colorR, colorG, colorB); | |
} | |
void printToLCD(){ | |
// Print a message to the LCD. | |
lcd.print("hello, world!"); | |
} | |
String IpAddress2String(const IPAddress& ipAddress) | |
{ | |
return String(ipAddress[0]) + String(".") +\ | |
String(ipAddress[1]) + String(".") +\ | |
String(ipAddress[2]) + String(".") +\ | |
String(ipAddress[3]) ; | |
} | |
void printWifiStatus() { | |
// print the SSID of the network you're attached to: | |
Serial.print("SSID: "); | |
Serial.println(WiFi.SSID()); | |
// print your WiFi shield's IP address: | |
IPAddress ip = WiFi.localIP(); | |
Serial.print("IP Address: "); | |
Serial.println(IpAddress2String(ip)); | |
// print the received signal strength: | |
long rssi = WiFi.RSSI(); | |
Serial.print("signal strength (RSSI):"); | |
Serial.print(rssi); | |
Serial.println(" dBm"); | |
} | |
void setupWifi(){ | |
//Initialize serial and wait for port to open: | |
Serial.begin(9600); | |
// check for the presence of the shield: | |
if (WiFi.status() == WL_NO_SHIELD) { | |
Serial.println("WiFi shield not present"); | |
// don't continue: | |
while (true); | |
} | |
String fv = WiFi.firmwareVersion(); | |
if (fv != "1.1.0") { | |
Serial.println("Please upgrade the firmware"); | |
} | |
// attempt to connect to Wifi network: | |
lcd.begin(16, 2); | |
while (status != WL_CONNECTED) { | |
lcd.setCursor(0,0); | |
lcd.write("Attempting.."); | |
delay(200); | |
Serial.print("Attempting to connect to SSID: "); | |
lcd.setCursor(0,1); | |
lcd.write(ssid); | |
delay(200); | |
Serial.println(ssid); | |
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | |
status = WiFi.begin(ssid); | |
// wait 10 seconds for connection: | |
delay(10000); | |
} | |
lcd.setCursor(0,0); | |
Serial.println("Connected to wifi"); | |
lcd.write("Connected!"); | |
printWifiStatus(); | |
} | |
void printUV(){ | |
//if(stat==ON){ | |
Serial.println("==================="); | |
Serial.print("Vis: "); Serial.println(uv.readVisible()); | |
Serial.print("IR: "); Serial.println(uv.readIR()); | |
int UVindex = uv.readUV(); | |
String UVindexString = String(UVindex); | |
if(UVindex<10){ | |
UVindexString = "00"+String(UVindex); | |
}else if(UVindex<100){ | |
UVindexString = "0"+String(UVindex); | |
} | |
Serial.print("UV (div100): ");Serial.println(UVindex); | |
String text = "UV (div100): "+ UVindexString; | |
printToLCD(text); | |
sendUVToApi(UVindex); | |
delay(5000); | |
//} | |
} | |
void setupUVSensor(){ | |
if (! uv.begin()) { | |
Serial.println("Didn't find Si1145"); | |
while (1); | |
} | |
} | |
void printToLCD(String& text){ | |
// Print a message to the LCD. | |
lcd.setCursor(0, 0); | |
lcd.print("UV Smart"); | |
lcd.setCursor(0, 1); | |
lcd.print(text); | |
} | |
void sendUVToApi(const int& UVindex){ | |
if (client.connect(server, 80)) { | |
IPAddress ip = WiFi.localIP(); | |
String getdata = "/uvapi?uv="+String(UVindex)+"&ir="+String(UVindex); | |
Serial.println("connected to server"); | |
// Make a HTTP request: | |
client.println("GET "+getdata+" HTTP/1.1"); | |
client.println("Host: "+String(server)); | |
client.println("Connection: close"); | |
client.println(); | |
Serial.println("/uvapi?uv="+String(UVindex)+"&ir="+IpAddress2String(ip)); | |
Serial.println("Sent! to "+String(server)); | |
Serial.println("disconnecting from server."); | |
client.stop(); | |
} | |
} | |
/********************************************************************************************************* | |
END FILE | |
*********************************************************************************************************/ |
from google.appengine.ext import db | |
class MiniDB(db.Model): | |
uv = db.StringProperty(required=False) | |
ir = db.StringProperty(required=False) | |
time = db.StringProperty(required=False) |
SpaceApps is a NASA incubator innovation program.