Greetings,
I would like to know if anyone else is using the UNO or MEGA for POSTING to:
“GET /weatherstation/updateweatherstation.php?” ?
I have been able to use the MEGA with an ADAFRUIT CC3000 WiFi BoB with some success and am wondering if anyone else has had some success . after random "posts’ the unit hangs for no known reason (i think it’s the CC3000 library hanging), so after FIVE loops i disconnect the CC3000 and reconnect to my router and start all over again.
My main thought is to simplify the “post” with all sensor data and text into one string to send it to wunderground so I can use the RAPID FIRE reporting. as i have it now it takes sometime to go line by line to send the data.
PART ONE of Full Code Below!
PART TWO NEXT POST
I am A learner, so be nice please
/***************************************************
* This is an example for the Adafruit CC3000 Wifi Breakout & Shield
*
* Designed specifically to work with the Adafruit WiFi products:
* ----> https://www.adafruit.com/products/1469
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Limor Fried & Kevin Townsend for Adafruit Industries.
* BSD license, all text above must be included in any redistribution
****************************************************/
/*
This example does a test of the TCP client capability:
* Initialization
* Optional: SSID scan
* AP connection
* DHCP printout
* DNS lookup
* Optional: Ping
* Connect to website and print out webpage contents
* Disconnect
SmartConfig is still beta and kind of works but is not fully vetted!
It might not work on all networks!
*/
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include "RTClib.h"
//Pins
#define led 12
#define anemometer 2 // Wind speed
//#define rainTip = 3; // Digital 3, Receive the pulse from Rain HALL EFFECT sensor on pin 3/Interupt 1
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#define DHTPIN A0 // DHT 22 (AM2302)
#define winDir A2 // Wind direction
#define WLAN_SECURITY WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS 3000 // Amount of time to wait (in milliseconds) with no data
#define period 5000 // Measurement period (miliseconds)
#define Wait 5000 // Amount of Time to wait till Re-connecting
#define WLAN_SSID "XXXXXXXXXXX" // cannot be longer than 32 characters!
#define WLAN_PASS "XXXXXXXXX"
#define ID "KFLFORTM63" //wunderground station
#define PASSWORD "XXXXXX"
//#define WEBSITE "rtupdate.wunderground.com"// RapidFire Server 2.5 sec interval
#define WEBSITE "weatherstation.wunderground.com"//standard server
#define WEBPAGE "GET /weatherstation/updateweatherstation.php?"
#define DHTTYPE DHT22 // DHT 22 (AM2302)
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
DHT dht(DHTPIN, DHTTYPE); // DHT 22 (AM2302)
Adafruit_BMP085 bmp; // BMP Sensor
RTC_DS1307 rtc;
const float pi = 3.14159265; // pi, not apple, not pumpkin, not pizza, not even related to Raspberry Pi. http://www.raspberrypi.org/ This is the REAL PI for Wind speed calculations
//int period = 5000; // Measurement period (miliseconds)
//int Wait = 5000; // Amount of Time to wait till Re-connecting
const int radio = 65; // Radius from vertical anemometer axis to a cup center (mm)
unsigned int counter = 0; // pulse count for wind sensor
unsigned int RPM = 0; // Revolutions per minute
unsigned int Sample = 0; // Sample number
//unsigned int timesConnected = 0; // WiFi conections
float speedwind = 0 / 0.445 ; // Wind speed (m/s)
float winddir = 0; // Wind direction
//---DEWPOINT
double dewPoint(double tempf, double Humi)
{
double A0= 373.15/(273.15 + tempf);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * Humi;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
//---DEWPOINT
uint32_t ip;
void setup(void)
{
Serial.begin(115200);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
bmp.begin();
Wire.begin();
pinMode(anemometer, INPUT);
digitalWrite(anemometer, HIGH);
rtc.begin();
//rtc.adjust(DateTime(__DATE__, __TIME__));
Serial.println(F("CC3000 Wunderground Test!\n"));
dht.begin();// Connect the DHT22 sensor
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
// Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
ip = 0;
Serial.print(WEBSITE);
Serial.print(F(" -> "));
while (ip == 0) {
if (! cc3000.getHostByName(WEBSITE, &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);
//timesConnected++;
Serial.println();
}
void loop(void)
{
if (Sample >= 5){
Sample = 0;
Serial.println(F("\n\nDisconnecting"));
cc3000.disconnect();
delay(10);
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
// Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
ip = 0;
Serial.print(WEBSITE);
Serial.print(F(" -> "));
while (ip == 0) {
if (! cc3000.getHostByName(WEBSITE, &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);
//timesConnected++;
Serial.println();
}
Sample ++;
windvelocity();
RPMcalc();
WindSpeed();
Heading();
float tempf = dht.readTemperature(2);
float Humi = dht.readHumidity();
float baromin = bmp.readPressure()* 0.0002953;
float maxwind = 0 / 0.445;
float Dew = (dewPoint(dht.readTemperature(2), dht.readHumidity()));
if (speedwind > maxwind) {
maxwind = speedwind;
}
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {
Serial.println("Sending DATA ");
digitalWrite(led, HIGH);
Serial.print(" Sample # ");
Serial.println(Sample);
Serial.println("-------------------------------------");
DateTime now = rtc.now();
// Serial.print(WEBSITE);
client.print("GET /weatherstation/updateweatherstation.php?");
client.print("ID=");
client.print(ID);
client.print("&PASSWORD=");
client.print(PASSWORD);
client.print("&dateutc=");
client.print(now.year());
client.print("-");
client.print(now.month());
client.print("-");
client.print(now.day());
client.print("+");
client.print(now.hour()+ 5);
client.print("%3A");
client.print(now.minute()+ 2);
client.print("%3A");
client.print(now.second());
digitalWrite(led, LOW);
client.print("&winddir=");
client.print(winddir);
digitalWrite(led, HIGH);
client.print("&windspeedmph=");
client.print(speedwind);
digitalWrite(led, LOW);
client.print("&windgustmph=");
client.print(maxwind);
digitalWrite(led, HIGH);
client.print("&rainin=0");
//client.print("0");
digitalWrite(led, LOW);
client.print("&tempf=");
client.print(tempf);
digitalWrite(led, HIGH);
client.print("&baromin=");
client.print(baromin);
digitalWrite(led, LOW);
client.print("&dewptf=");
client.print(Dew);
digitalWrite(led, HIGH);
client.print("&humidity=");
client.print(Humi);
digitalWrite(led, LOW);
client.print("&action=updateraw");
client.println();
digitalWrite(led, HIGH);
//delay(10);
digitalWrite(led, LOW);
}
else {
Serial.println(F("Connection failed"));
return;
}
Serial.println("Server Responce!");
unsigned long lastRead = millis();
while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
client.close();
Serial.println("-------------------------------------");
Serial.print("Waiting ");
Serial.print(Wait/1000.0);
Serial.println(" seconds.");
delay(Wait);// 30sec
Serial.println();
Serial.println("-------------------------------------");
}//end loop