Download Print this page

sparkfun Wimp Manual

Weather station wirelessly connected to wunderground

Advertisement

Quick Links

Weather Station Wirelessly Connected to Wunderground
CONTRIBUTORS:
NATE
FAVORITE
19
Wimp Weather
The Wimp is a personal weather station that uses the weather shield along with an Electric Imp to push live weather data up to Wunderground. You can help increase
the accuracy and prediction of weather by adding a weather meter to your house! But why buy an off-the-shelf system when you can build you own? For around
$250 you can build a cutting edge open source station that you have complete control over! All you need is a pile of parts and access to a Wifi network.
Wunderground makes it really easy to setup your own weather station. You fill out a form, pick a username and password, then get a station ID. Using this ID and
password, we can push weather data with a simple HTTP POST command:
http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?ID=KCOBOULD115&PASSWORD=SparkFun&dateutc=2014-07-02+03%3A32%3A42&windd
ir=270&windspeedmph=7.0humidity=45.4&tempf=43.1&baromin=29.4161&realtime=1&rtfreq=10&action=updateraw
Copy and paste the above code into a browser, and press return. You should see
then view the weather station data you just posted here. Congrats! You've just published your first weather data to the Internet of Things.
The above link shows how to push temperature data to the web, but you can also post a large number of other weather metrics. This example will show you how to
report the following bits of weather:
Temperature
Humidity
Light level
Rain fall
Instantaneous Wind speed + direction
Gusting speed + direction for the last 2 minutes
Gusting speed + direction for the last 60 minutes
Live weather in downtown Boulder
. Note: You may have to modify the 2014-07-01 to today's date. You can
success

Advertisement

loading
Need help?

Need help?

Do you have a question about the Wimp and is the answer not in the manual?

Questions and answers

Summary of Contents for sparkfun Wimp

  • Page 1 Wimp Weather The Wimp is a personal weather station that uses the weather shield along with an Electric Imp to push live weather data up to Wunderground. You can help increase the accuracy and prediction of weather by adding a weather meter to your house! But why buy an off-the-shelf system when you can build you own? For around $250 you can build a cutting edge open source station that you have complete control over! All you need is a pile of parts and access to a Wifi network.
  • Page 2 Weather data on data.sparkfun.com You can also see even more data at the Wimp Weather Stations channel over on data.sparkfun.com. This channel includes some extra bits including battery voltage level, ambient light level, and local time stamp (including DST correction).
  • Page 3: Weather Shield

    RedBoard This is our Arduino-compatible workhorse. It will gather all the weather data from the weather shield and then pipe serial strings to the Imp. Weather Shield You can read all about the Weather Shield over on its hookup guide tutorial. All you really need to know is that it’s capable of reading a huge number of weather metrics but doesn’t have the capabilities to wirelessly report them.
  • Page 4: Power System

    Weather station stackup with solar charger and 2000mAh battery. Final installation uses a 6000mAh battery. The Wimp runs off a 3.7V 6000mAh LiPo battery. The following measurements were taken for various bits of the project: Electric Imp (average when posting data every 5 seconds): [4.5mA during sleep for 8s, 80-100mA for 2s] = 22mA avg...
  • Page 5 Our plastic red enclosure is very robust against adverse weather and is easily modified with tools found at home (hand drill, dremel, etc). The problem is that depending on where you want to mount your weather station, the red box enclosure can heat up quite a bit. In Colorado direct sunlight can be quite intense, so do plenty of Googling to determine what’s best for you.
  • Page 6 Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide. Below, you will find example code, but, for the latest version of everything, see the Wimp github repo.
  • Page 7 Weather Station using the Electric Imp By: Nathan Seidle SparkFun Electronics Date: October 4th, 2013 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). Much of this is based on Mike Grusin's USB Weather Board code.
  • Page 8 //Wind speed/dir, avg over 2 minutes (store 1 per second) //Wind gust/dir over last 10 minutes (store 1 per minute) //Rain over the past hour (store 1 per minute) //Total rain over date (store one per day) byte windspdavg[120]; //120 bytes to keep track of 2 minute average #define WIND_DIR_AVG_SIZE 120 int winddiravg[WIND_DIR_AVG_SIZE];...
  • Page 9 // attach external interrupt pins to IRQ functions attachInterrupt(0, rainIRQ, FALLING); attachInterrupt(1, wspeedIRQ, FALLING); // turn on interrupts interrupts(); Serial.println("Wimp Weather Station online!"); reportWeather(); wdt_enable(WDTO_1S); //Unleash the beast void loop() wdt_reset(); //Pet the dog //Keep track of which minute it is if(millis() - lastSecond >= 1000)
  • Page 10 //We've got something! lightning_distance = readLightning(); #endif //Wait for the imp to ping us with the ! character if(Serial.available()) byte incoming = Serial.read(); if(incoming == '!') reportWeather(); //Send all the current readings out the imp and to its agent for posting to wunderground. Takes 196ms //Serial.print("Pinged!");...
  • Page 11 dailyrainin = 0; //Reset daily amount of rain windgustmph = 0; //Zero out the windgust for the day windgustdir = 0; //Zero out the gust direction for the day minutes = 0; //Reset minute tracker seconds = 0; lastSecond = millis(); //Reset variable used to track minutes minutesSinceLastReset = 0;...
  • Page 12 //Calc light level light_lvl = get_light_level(); //Calc battery level batt_lvl = get_battery_level(); //Lightning is checked in the main loop //Returns the voltage of the light sensor based on the 3.3V rail //This allows us to ignore what VCC might be (an Arduino plugged into USB has VCC of 4.5 to 5.2V) float get_light_level() float operatingVoltage = averageAnalogRead(REFERENCE_3V3);...
  • Page 13 if (adc < 878) return (338); if (adc < 913) return (0); if (adc < 940) return (293); if (adc < 967) return (315); if (adc < 990) return (270); return (-1); // error, disconnected? //Reports the weather string to the Imp void reportWeather() calcWeather();...
  • Page 14 //Serial.println("Noise level too high, try adjusting noise floor"); if (irqSource & 0b0100) //Serial.println("Disturber detected"); distance = 64; if (irqSource & 0b1000) // need to find how far that lightning stroke, function returns approximate distance in kilometers, // where value 1 represents storm in detector's near victinity, and 63 - very distant, out of range stroke // everything in between is just distance in kilometers distance = AS3935.lightningDistanceKm();...
  • Page 15 Load the code onto your RedBoard (or Arduino of choice). Open a terminal window at 9600bps. You should see new weather data upon power up and every time you send the character.
  • Page 16 // This agent gathers data from the device and pushes to Wunderground // Talks to wunderground rapid fire server (updates of up to once every 10 sec) // by: Nathan Seidle SparkFun Electronics // date: October 4, 2013 // license: BeerWare Please use, reuse, and modify this code as you need.
  • Page 17 pline .data <- program .readblob (ARDUINO_BLOB_SIZE ); pline .addr <- addr / 2; // Address space is 16-bit device .send("burn", pline) addr += pline.data.len(); device .send("burn", {last=true}); //------------------------------------------------------------------------------------------------------------------------------ // Parse the hex into an array of blobs function parse_hexfile (hex) { try { // Look at this doc to work out what we need and don't.
  • Page 18 //------------------------------------------------------------------------------------------------------------------------------ // Handle the agent requests http.onrequest (function (req, res) { // return res.send(400, "Bad request"); // server.log(req.method + " to " + req.path) if (req.method == "GET") { res .send(200, html); } else if (req.method == "POST") { if ("content-type" in req.headers ) { if (req.headers ["content-type"...
  • Page 19 = windCorrect (windgustdir ); winddir_avg2m = windCorrect (winddir_avg2m ); windgustdir_10m = windCorrect (windgustdir_10m ); //Correct for negative temperatures. This is fixed in the latest libraries: https://learn.sparkfun.com/tutorials/mpl3115a2-pre currentTemp <- mysplit (tempf, '='); local badTempf = currentTemp [1].tointeger (); if(badTempf > 200) local tempc = (badTempf - 32) * 5/9;...
  • Page 20 = "measurementtime=" + calcLocalTime (); //Now post to data.sparkfun.com //Here is a list of datums: measurementTime, winddir, windspeedmph, windgustmph, windgustdir, windspdmph_avg2m, winddir_avg2m, //Now we form the large string to pass to sparkfun local strSparkFun = "http://data.sparkfun.com/input/" ; local privateKey = "private_key=" + sparkfun_privateKey ;...
  • Page 21 dewPoint = dewPoint * 9 / 5.0 + 32; //server.log("rh=" + relativeHumidity + " tempF=" + tempF + " tempC=" + tempC); //server.log("DewPoint = " + dewPoint); return(dewPoint ); function checkMidnight (ignore) { //Check to see if it's midnight. If it is, send @ to Arduino to reset time based variables //Get the local time that this measurement was taken local localTime = calcLocalTime ();...
  • Page 22 //Given UTC time and a local offset and a date, calculate the local time //Includes a daylight savings time calc for the US function calcLocalTime () //Get the time that this measurement was taken local currentTime = date(time(), 'u'); local hour = currentTime .hour; //Most of the work will be on the current hour //Since 2007 DST starts on the second Sunday in March and ends the first Sunday of November //Let's just assume it's going to be this way for awhile (silly US government!) //Example from: http://stackoverflow.com/questions/5590429/calculating-daylight-savings-time-from-only-date...
  • Page 23 break; case 3: month_lookup = 3; //March = 3 break; case 4: month_lookup = 6; //April = 6 break; case 5: month_lookup = 1; //May = 1 break; case 6: month_lookup = 4; //June = 4 break; case 7: month_lookup = 6; //July = 6 break;...
  • Page 24 // Reads data from a station and pushes it to an agent // Agent then pushes the weather data to Wunderground // by: Nathan Seidle SparkFun Electronics // date: October 4, 2013 // license: BeerWare Please use, reuse, and modify this code as you need.
  • Page 25 const STK_READ_PAGE = 0x74; // 't' const STK_READ_SIGN = 0x75; // 'u' const STK_READ_OSCCAL = 0x76; // 'v' const STK_READ_FUSE_EXT = 0x77; // 'w' const STK_READ_OSCCAL_EXT = 0x78; // 'x' //------------------------------------------------------------------------------------------------------------------------------ function HEXDUMP (buf, len = null) { if (buf == null) return "null"; if (len == null) { len = (typeof buf == "blob") ? buf.tell() : buf.len();...
  • Page 26 // server.log("Sending: " + HEXDUMP(send_buffer)); SERIAL .write(send_buffer ); local resp_buffer = SERIAL_READ (response_length +2, response_timeout ); // server.log("Received: " + HEXDUMP(resp_buffer)); assert(resp_buffer != null); assert(resp_buffer .tell() >= 2); assert(resp_buffer [0] == STK_INSYNC ); assert(resp_buffer [resp_buffer .tell()-1] == STK_OK ); local tell = resp_buffer .tell(); if (tell == 2) return blob(0);...
  • Page 27 } while (ch != -1); if (str.len() > 0) { server .log("Serial: " + str); //------------------------------------------------------------------------------------------------------------------------------ function burn(pline) { if ("first" in pline) { server .log("Starting to burn" ); SERIAL .configure (115200, 8, PARITY_NONE , 1, NO_CTSRTS ); bounce (); } else if ("last"...
  • Page 28: How It Works

    if(result == NOCHAR ) imp .sleep(0.01); if(counter ++ > 20) //Wait no more than 20ms for another character server .log("Serial timeout error" ); return(0); //Bail after 20ms max wait //server.log("Test: " + format("%c", result)); // Display in log window incomingStream += format ("%c", result ); toggleTxLED ();...
  • Page 29 The Agent receives this string and cracks it apart into its pieces. Because the RedBoard has pretty limited resources, we report raw Pascals to the Imp and let the Agent do the complex mmHg pressure and dew point calculations. Once all the pieces are calculated, we create another big string that is an http:// address. Posting this long link causes the weather data to be transmitted to Wunderground.
  • Page 30: Lessons Learned

    A common problem in Colorado The incline angle of the solar panel was not scientifically determined - I pointed the solar panel to the south with about a 45 degree angle. This is a common orientation in Colorado, but there are plenty of solar angle calculators available to help you determine the best inclination for your part of the world. Ballast Because the winds are so strong in our area, I wanted to be sure to attach the base to as much ballast as possible.
  • Page 31 The first setup This first setup used zip ties to tension the two blocks to the base of the tripod. Unfortunately I had some really bad zip ties. You know - the ones that snap or release as soon as you put a bit of force behind them? I know this attachment system was questionable, but note the snow and my decision to start this project in December. Adding turnbuckles After a bit of Googling, I discovered these things called turnbuckles! Wow they work.
  • Page 32 Lesson 2 - Make it Accessible Above all else, put the Wimp where it can be easily maintained. Things will break - be sure you can access your weather station with as little danger as possible. You may think you’ll only have to do maintenance on the weather station once a year. If you’re building your own, plan to be in the station once a week in the beginning and once a month after you get it up and running.
  • Page 33 This was a big tutorial to write! We hope you’ve enjoyed it. If you’ve got similar weather projects or lessons, please let us know. Extra Resources: Read more about the Electric Imp Pushing data to data.sparkfun.com Hacking MindWave Mobile Making Simon Says Wireless...