Saturday, March 11, 2017

Parenting Month 76: No longer one of the little kids

The major milestone of the kids is the 6 year old has had his last American Taekwondo Association (ATA) Tigers belt testing.  In the ATA, the Tigers is the group for 4-6 year olds where they allow for follow the leader in testing and advance at half speed (in each testing, they cover half of the form that the older groups do. Developmentally, this makes a lot of sense, somewhere around 7-8 kids begin to reliably tell left from right and there sense of time and sequencing develops.  However, at this school, they join the older kids (7-12) after the first half of blue belt (i.e. they will test for brown belt with the older kids).  At this testing cycle, he is the only one to advance due to belt promotion (there are two others doing the same, but because they turned 7)


ATA color belt testing
Blue belt testing.

One thing we have appreciated about his taekwondo classes and tournaments is that he has been one of the smallest ones, but has generally been one of the more focused kids, which results in him being noticeably more in line with the class than the others his age. And the way that manifests itself is that the teachers use him to flex pairings during sparring or self-defense testing, he will match his partner. While generally they try to match kids on size and temperament, they can pair him with smaller or shyer kids because he won't bully people over.  And with the bigger kids, he has enough skill that he will not get knocked over or hurt.

But now that he is with the older kids, as the youngest and one of the smallest in the room (there is one smaller). And we actually like it that way. We have always felt that we wanted him to be comparing himself to kids who were older, bigger, and smarter than him, so that there would always be someone ahead of him and he would always know what better looks like.  We have appreciated this in Taekwondo, where the teaching philosophy is that at whatever level a student was, the aim of the day's lesson was to always get better.
ATA color belt testing
High block


We think that T has shined in this setting, and anyplace like that where we have been able to create that. We get worried when he gets too many accolades this young, because we want him to be ready for the challenges in the future. And at this age, it is best if he is always learning and competing with people who have natural advantages over him, so when that changes, he will do well.

Friday, February 03, 2017

Parenting Month 75: A is for Attitude

Our two year old is speaking more and more. As foreshadowed by many events, she talks, pretty much non-stop.  And if she was able to proclaim her will when she was 18 months and not actually knowing words, she show guile now that she actually has english and chinese vocabulary.  While big brother is getting pretty good to, it is even money on whether he is learning from his classmates, or if he is learning guile from his little sister.

On the other side of the equation, we are seeing that there is tradeoff.  While little sister clearly is well beyond what big brother was like verbally and socially, we remember how generally agreeable and happy he was in simple ways. And especially the fact that big brother could concentrate on something for extended periods of time.  And the effect is that while there are things that little sister does that big brother did not at the same age, there were many opportunities we could provide big brother at that age because he was so well controlled and he could focus and be satisfied with one thing for extended periods of time.  If you asked us who is smarter, we both would say little sister, but big brother could maintain his attention and stick to things longer that she can now.  And that is starting to show the difference.

T has been learning how to lie. And we suspect he is picking this up at school, because when he does, he has this habit of looking to see if it was successful. So whenever we notice that pause, we start to think about what has he just said. At this point, it is experimentation.  He is also still very bad at hiding things. One little habit he has is when he makes a mess on something. He will come along and ask for things that happen to be cleaning supplies, and inform us that there is no need for us to go look at ___.  At this point, while we immediately go look, we are being good at merely helping him clean up after himself. And hoping he does not get better at hiding.

Last, we have a couple more events. His first college basketball game:


Pitt women's basketball friends and family day
Getting a tiger named T, because then if there is trouble, he can say that T did it without lying.

Pitt women's basketball friends and family day
Presenting the colors for the national anthem



Pitt women's basketball friends and family day
Pitt colors at the Pitt game

Friday, December 30, 2016

Parenting Month 74: New environments

The highlight of the month has been two weeks in Thailand. We have had a desire to make sure that our kids experience a world that is different than the upper middle class suburbia we live in.  In contrast, our family in Bangkok, Thailand is in the middle of a city of 8 million people and is a place where wealth lives side-by-side with poverty, much different than the U.S. where we are very segregated economically.


Jumping on the boat at the pier
Someone jumping onto a riverboat before it leaves the pier


T experienced a number of new experiences.  He used a river boat that was a means of transportation (not just a tourist boat), he rode a tuk-tuk (2 stroke engine powered tricycle-cab), and walked down a street market daily.

Wai phra at the local street market
Wai Phra to a monk on the street market on Petchburi Soi 5
Dodging traffic on a Soi
Letting some cars go by in the morning street market
Our general approach to raising our children has been encouraging competence. This has included skills such as woodworking, using tools, and generally toys that involve building. But we also want to include social competence, meaning that they can function in a world different than the suburban upper middle class world we live in.  So on this trip we did some normal tourist things like going to the malls and temples, but we also did things that were closer to how life was lived, like going to the local street market every day to get food for breakfast, or traveling by river boat on commuter boats (as opposed to the tourist boat). We taught him how to read maps for train and boat, to practice social curtesies with everyone, and to become more aware of his surroundings. 

He obviously stands out. The very casual dress compared to school kids, the fact that he bounces along as he walks would make him stand out even if he was not speaking english. And in social status conscious Thailand, this particularly makes him stand out as many service personnel have gotten used to not having their curtesies returned by those of higher social class, so my six year old stands out from greeting everyone he interacts with properly.

When I was in Afghanistan, I had spoken frequently with a former CIA officer on a range of topics. One day he commented that I was someone who could go anywhere in the world and learn to interact with anyone. Now, that is not true, I spent much of my growing up years just trying to reduce how much I got yelled at instead of building competencies, and I was still getting used to being in a place where it was acceptable to act when lives were in danger. But being a parent, I can think about what it would take to actually be such a person. And that would include learning to function in new environments, with new social rules and requirements, and new patterns of life. Even now as someone this young.

We hope that he will experience three cultures growing up: the U.S., Thailand, and China. And that this could be a springboard for being the type of person my colleague talked about. 

Riding a river boat on the Chao Praya river
Riding a river boat

Thailand 2016 Trip anecdotes part 2


  • T playing with a 4 year old Thai girl. They do not have a common language, but one of their games is to whisper in each other's ear. 
  • Realizing that said 4 year old has never colored (with crayons) before.
  • Said 4 year old trying to quiet down A's tantrum by shushing her. 
  • We think that she likes the fact that there is someone in the family compound that is younger than her. 
  • Our go to method for shortstopping a two year old tantrum, get her singing. A sang alot this trip.
  • People on the BTS train offering us their seats because we have young children with us. This happened every single time. (Except Christmas Eve, which is why A singing was so exceptional that night.) 
  • I got a lot of exercise carrying around A in a ring sling.
  • The boys went to see Rogue One. This is T's third movie in a theater.
  • At my father's one year remembrance, T was told to watch the door and greet (wai) everyone who came in, and he did. 
  • T going to the street market on his last morning to give food to the monk, and chatting with the monk after the blessing. 
  • I don't think I'll get used to being greeted by 'sawasdee pii' from professional adults ('pii' refers to someone older, I'm used to using it to refer to older kids, not adults)
  • A likes to pass the time by singing songs she knows from daycare or YouTube videos. Our soundtrack from the vacation is highlighted by Everything is Awesome, the LEGO Movie theme song by The Lonely Island 
  • T passes time by singing songs from school. We are starting to suspect that he is making up lyrics for the songs. 
  • On the trip back, we had to walk a long way between gates to catch a connection, A saying to T "keep walking" (they had been watching Finding Dory on the plane, Dory's catch phrase is "keep swimming") 
  • Waiting at O'hare for the last leg, A was singing and dancing in the waiting area. Completely inappropriate for a 2 year old who left grandma's house over 24 hours ago. 
  • A woke up around 2 AM for her morning concert. Which is when I am writing this.

Saturday, December 24, 2016

Thailand 2016 trip Part 1


  • T 6yrs old.  On encountering turbulence.  "This is fun!"  By the end of a flight which included an aborted landing due to a wind shear alarm, he threw up. 2yr old sister was not far behind.
  • By the end of the D.C. -Tokyo leg, commentary from other passengers, if they are this agreeable when tired and uncomfortable, they must be wonderful children from day to day.
  • Tokyo airport play area. We meet someone we know and our kids play for a while.
  • 5:30 in the morning wake up to roosters crowing. 2 yr old had been awake since 3 and thinks she has company in her morning concert. She knows that roosters say Cock-a-doo-doo 
  • First of many trips to the next soi (small street) market over to get morning breakfast. T learns to give food to the local monk. The next day we find out that the monk we picked can speak English. Wai phra becomes our daily ritual and we are usually not rushed by others waiting their turn so we can talk with the monk.
  • Cousin has a piano. That means T has daily piano practice. 
  • Visit great-grandma. T is getting the wai for hello thing down.
  • By the third morning T and I have made the first trip with just the two of us. T has learned to wai and say sawasdee khrab to every vendor we buy something from. We have gotten a discount from one vendor who knows that a 6 yr old boy is learning how to wai phra. People ask about his mother. Random people want to say hello. We get freebies when we buy things in the morning market.
  • Take train and boat to go to Museum of Siam. They are closed for renovation for the month. Major fail. T thinks that the boat trips on the river express boat were really cool. Maybe not so bad.
  • Go to Kasetsart to give a talk. The guy picking me up from the train station asks what am I wearing so he can recognize me. Thailand is in morning so everyone is wearing white or black, including me. I suggest my green bag is more identifiable.
  • Change the morning workshop based on the conversation over the drive. Three hour workshop, with two hours created as we go. It did not completely fall apart. Everyone learned a lot. 
  • Faculty member teased because we were talking about exchange programs, and she is thinking about what her daughter will do. Said daughter is currently 5.
  • Conversations at a couple of universities focusing on the difficulty in teaching programming to engineers. Everyone is relieved to know that they are not the only ones. Conversation then moves to how some places are trying to improve it.
  • This morning's market run was with grandma and granddaughter, but without grandson. Everyone asks what happened to grandson. We do not get our usual freebies. We can now put an economic value on the difference in cuteness between a very well behaved 6yr old boy vs a shy 2 yr old girl.
  • T and I go without mommy and sister to Siriraj medical Museum. We get to see actual hearts, lungs, etc in various states of health, including smokers, gun shot victims, stabbing victims. We are pretty sure that is unique in his first grade class.
  • Shop girls love T. Museum staff girls want pictures with him.  Maybe we should charge for the privilege.
  • 2 yr olds having a get home by __ spell means we can define an effective radius that we can have dinner if we want to go out.
  • Go out for a late dinner that involves taking a boat. We get recognized by a family that was on the boat with us this morning.
  • Lunch, I find a table with a sleeping A while everyone is finding lunch at a food court. Lady comes over and tries to help wake up and feed A. (If you did not know, Thai girls rival Japanese girls in their attraction to things cute, and my kids count when they are with us)
  • Christmas Eve on a very crowded BTS system with lots of tired and cranky people. A is sitting in a sling and is singing away happily. Most people are too tired to appreciate how cute that is, but there were a few.
  • Tired T, very happy to take a trip in a Tuk-tuk. Includes laughing at another family who was also crammed in another tuk-tuk and a motorcycle riding Santa Claus.

Thursday, November 24, 2016

Sally Steel and the Miniature Menace by Cally Harris: Book Review

Sally Steel series are pulp fiction aimed at young adults (middle school).  What pulp means is that the characters are generally or specifically competent. The young adult target implies that some of the conflicts are those that are of special interest to young adults.

The setting is midwestern farm country in the early 1900s, and Sally Steel is a teenage girl. Who happens to be gifted in all things mechanical. This leads to a number of problems in her life. Largely due to the fact that she is a girl. And there are expectations of girls in that setting. So she gets teased because she is a girl with her interests, because she is good, she is prevented from getting recognition by society so she does not upstage the boys. Her father chooses to be blind to her abilities (but her mother and brothers all see it).

The meat of the story is Sally being caught up in an adventure with her good friend, Jet Black (whose main character trait seems to be fearlessly going into danger). And, it turns out that there are intelligent, reasonable, and capable adults that she runs into who are also allies. but, this being a Young Adult novel, she has to learn that she does not handle everything by herself.

As a story, it is a fun one. Sally and friends get into and out of trouble at a pretty good pace. The meet friends and enemies, and false friends one after another. For those who are familiar with the Dinocolypse series from the same publisher that features older versions of the same characters, it seems like the book was trying a little to hard to fit everyone in (it is a bit of a stretch to think that the people whose actions will affect the world happened to be the same age and cross paths in rural Illinois as teenagers).

But at its heart, pulp is a story about heros who are capable, in this case, even a hero that is a teenage girl. And it is a fun story at that.

Saturday, November 05, 2016

Parenting month 72: Maker vs consumer

Another year. Since T's birthday I've probably said that he was five at least five times.  It is hard to get into the mindset that they don't freeze in time.

Some highlights of this year:

1. Movies on the big screen: The Martian and MacGillivray Freeman's Humpback Whales.
2. Live professional sporting events:  The Washington (PA) Wild Things and the Pittsburgh Pirates
3. Playing on a sports team:  Eagles Soccer
4. Taekwondo rank. Purple belt (ATA taekwondo)
5. Starting first grade


Playing a Circuit Playground fruit piano at Makerfaire
Demonstrating a fruit piano
Some changes over the past month.

1. Social  -  Teachers report that he is apparently everyone's best friend. However, he is still a  relatively controlled one in the class. They report that he regards the overall silliness and chaos of first grade but does not actually take part.
2. Making - We have been trying to get him to regard activities as one where he is a consumer to one where he is an active part in its creation. So it means showing people how things work and being part of the entertainment (i.e. playing piano in public) His old habit of freezing in public performance seems to be overcome, with a few public performances without a hitch. He is freer about talking to strangers, but not on command (i.e. we would like him to be able to demonstrate things he knows, not talk to random strangers without cause).  One thing is that he is better about asking questions and requesting opportunities, which got him some nice experiences at times.
3. Soccer is over. While a good experience, we're pretty sure he does not have any desire to do this again. Nothing against soccer, but he realizes that he sacrificed taekwondo for it, and he also notices that a lot of things he used to do on Saturdays got pushed out because soccer takes out the flexibility of his weekends.
4. Sense of urgency/speed. His teachers observed that he knows how to do anything asked of him, but he does it slowly. A big reason is that we did not drill him in anything over the summer, which is how you develop speed, especially in arithmetic.  So we started him on the online math program his school uses (some of the activities are timed, the first times he did them he timed out, he has gotten much better) and mommy school has started to include drilling.


This is how to program the Lego robot
Learning to program a LEGO robot
Taking apart a battlebot to fix it
Taking part in maintenance of a battle bot
We had one existential crisis. We found out from one of the teachers that some of the other kids in first grade learned multiplication over the summer. And we did no such thing, making us wonder if there was anything else we did not do! The teachers have assured us that they did not actually want us to teach him multiplication or other things, but the fact that they noted that some of the kids did (and that they had immediate recall from memorizing their times tables) makes us take that skepticism with a dash of salt.

A (2 1/2 years) has become more comfortable with day care. Now she waves goodbye at dropoff without a glance back. Teachers report that she sings alot.  What we notice is that she is much more talkative.  Her extended babbling at 18 months have converted to non-stop talking and singing.  We just took a 2 hour road trip where she was singing and telling stories to herself for the entire trip.

Friday, October 28, 2016

ESP8266 Thing board based environmental monitor

The goal of this project was to create an automatic temperature and light level monitor for a bioshelter (greenhouse +) run by The Bible Center Oasis Project (Pittsburgh, PA).  Because it would be used to grow flora and fauna, it needed ongoing monitoring of temperature and light levels to confirm that it would support the growth of food, and to monitor the effectiveness of measures being explored to control environmental conditions.


Homewood, Pittsburgh , PA
Bible Center Oasis Project bioshelter in Homewood (Pittsburgh), PA


As an off-grid, solar powered greenhouse, the bioshelter is not connected to any utilities. So any environmental monitoring solution needed to be low powered and use wi-fi for communication (i.e. no phone line). We also preferred solutions that did not force a subscription to a specific data logging service.

Temperature, humidity and light monitor
Sparkfun ESP8266 Thing Dev board based monitor

I developed a solution based on the Sparkfun ESP8266 Thing development board. This board provided the Arduino microcontroller to control the project and on-board wifi with antenna.  The other major components of the board were:
I first soldered headers onto the ESP8266 Thing dev board and the BME280 and TSL2561 breakout boards. These allowed for use of two mini-breadboards to develop the monitor, which also served as a base for the project when deployed.

The Thing dev board and both breakout boards were set up with Inter-integrated Circuit (I2C), protocol, so both sensor boards were connected to the I2C inputs on the Thing dev board.

The Thing dev board was then programmed to transmit the response to a phant server. Specifically, the data.sparkfun.com server that is  made freely available by Sparkfun.  In addition to being a data display, the phant server allows for accessing the data as csv or json files for further analysis, or using analog.io (link opens up the live graph of data. analog.io an IoT platform made available by Luke Beno).   Because phant also exposes the data in JSON format, my usual way of working with the data is to use the jsonlite package within R.

Breadboard diagram of ESP8266 with BME280 and TSL2561


Arduino *.ino code
 
1:  // Include the ESP8266 WiFi library. (Works a lot like the  
2:  // Arduino WiFi library.)  
3:  // Uses BME280 and TSL2561 to record temperature, pressure, humidity, and lux data to phant  
4:  // Code  
5:  //   
6:  #include ;  
7:  #include ;  
8:  #include ;  
9:  #include "Wire.h"  
10:  #include "SPI.h"  
11:  // Include the SparkFun Phant library.  
12:  #include ;  
13:  // Include SparkFun BME280 library  
14:  #include "SparkFunBME280.h"  
15:  //Global sensor object  
16:  BME280 mySensor;  
17:  // SFE_TSL2561 object  
18:  SFE_TSL2561 light;  
19:  //////////////////////  
20:  // WiFi Definitions //  
21:  //////////////////////  
22:  const char WiFiSSID[] = "ssid";  
23:  const char WiFiPSK[] = "psk";  
24:  /////////////////////  
25:  // Pin Definitions //  
26:  /////////////////////  
27:  const int LED_PIN = 5; // Thing's onboard, green LED  
28:  const int ANALOG_PIN = A0; // The only analog pin on the Thing  
29:  const int DIGITAL_PIN = 12; // Digital pin to be read  
30:  ////////////////  
31:  // Phant Keys //  
32:  ////////////////  
33:  const char PhantHost[] = "data.sparkfun.com";  
34:  const char PublicKey[] = "publickey";  
35:  const char PrivateKey[] = "privatekey";  
36:  /////////////////  
37:  // Post Timing //  
38:  /////////////////  
39:  const unsigned long postRate = 1000*60 * 30;  
40:  unsigned long lastPost = 0;  
41:  // Global variables for TSL2561:  
42:  boolean gain;   // Gain setting, 0 = X1, 1 = X16;  
43:  unsigned int ms; // Integration ("shutter") time in milliseconds  
44:  void setup()  
45:  {  
46:   // initHardware(); // Setup input/output I/O pins  
47:   connectWiFi(); // Connect to WiFi  
48:   digitalWrite(LED_PIN, LOW); // LED on to indicate connect success  
49:   //For I2C, enable the following and disable the SPI section  
50:   mySensor.settings.commInterface = I2C_MODE;  
51:   mySensor.settings.I2CAddress = 0x77;  
52:   //***Operation settings*****************************//  
53:   mySensor.settings.runMode = 3; // 3, Normal mode  
54:   mySensor.settings.tStandby = 0; // 0, 0.5ms  
55:   mySensor.settings.filter = 0; // 0, filter off  
56:   //tempOverSample can be:  
57:   // 0, skipped  
58:   // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively  
59:   mySensor.settings.tempOverSample = 1;  
60:   //pressOverSample can be:  
61:   // 0, skipped  
62:   // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively  
63:    mySensor.settings.pressOverSample = 1;  
64:   //humidOverSample can be:  
65:   // 0, skipped  
66:   // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively  
67:   mySensor.settings.humidOverSample = 1;  
68:   // Initialize the SFE_TSL2561 library  
69:   // You can pass nothing to light.begin() for the default I2C address (0x39),  
70:   // or use one of the following presets if you have changed  
71:   // the ADDR jumper on the board:  
72:   // TSL2561_ADDR_0 address with '0' shorted on board (0x29)  
73:   // TSL2561_ADDR  default address (0x39)  
74:   // TSL2561_ADDR_1 address with '1' shorted on board (0x49)  
75:   // For more information see the hookup guide at: https://learn.sparkfun.com/tutorials/getting-started-with-the-tsl2561-luminosity-sensor  
76:   light.begin();  
77:   Serial.begin(57600);  
78:   Serial.print("Program Started\n");  
79:  // The light sensor has a default integration time of 402ms,  
80:   // and a default gain of low (1X).  
81:   // If you would like to change either of these, you can  
82:   // do so using the setTiming() command.  
83:   // If gain = false (0), device is set to low gain (1X)  
84:   // If gain = high (1), device is set to high gain (16X)  
85:   gain = 0;  
86:   // If time = 0, integration will be 13.7ms  
87:   // If time = 1, integration will be 101ms  
88:   // If time = 2, integration will be 402ms  
89:   // If time = 3, use manual start / stop to perform your own integration  
90:   // Use time = 1 so that the midday sun does not lead to an error  
91:   unsigned char time = 1;  
92:   // setTiming() will set the third parameter (ms) to the  
93:   // requested integration time in ms (this will be useful later):  
94:   Serial.println("Set timing for TSL2561...");  
95:   light.setTiming(gain,time,ms);  
96:   // To start taking measurements, power up the sensor:  
97:   Serial.println("Powerup light sensor...");  
98:   light.setPowerUp();  
99:   // The sensor will now gather light during the integration time.  
100:   // After the specified time, you can retrieve the result from the sensor.  
101:   // Once a measurement occurs, another integration period will start.  
102:   Serial.print("Starting BME280... result of .begin(): 0x");  
103:   delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.  
104:   //Calling .begin() causes the settings to be loaded  
105:   Serial.println(mySensor.begin(), HEX);  
106:  }  
107:  void loop()  
108:  {  
109:   unsigned int delaytime;  
110:   Serial.println("Posting to Phant!");  
111:   if (postToPhant())  
112:   {  
113:    lastPost = millis();  
114:    Serial.println("Post Suceeded!");  
115:   }  
116:   else // If the Phant post failed  
117:   {  
118:    Serial.println("Post failed, will try again.");  
119:   }  
120:   delaytime = postRate;  
121:   delay(delaytime); // Short delay, then next post  
122:  }  
123:  void connectWiFi()  
124:  {  
125:   byte ledStatus = LOW;  
126:   Serial.println();  
127:   Serial.println("Connecting to: " + String(WiFiSSID));  
128:   // Set WiFi mode to station (as opposed to AP or AP_STA)  
129:   WiFi.mode(WIFI_STA);  
130:   // WiFI.begin([ssid], [passkey]) initiates a WiFI connection  
131:   // to the stated [ssid], using the [passkey] as a WPA, WPA2,  
132:   // or WEP passphrase.  
133:   WiFi.begin(WiFiSSID, WiFiPSK);  
134:   // Use the WiFi.status() function to check if the ESP8266  
135:   // is connected to a WiFi network.  
136:   while (WiFi.status() != WL_CONNECTED)  
137:   {  
138:    // Blink the LED  
139:    digitalWrite(LED_PIN, ledStatus); // Write LED high/low  
140:    ledStatus = (ledStatus == HIGH) ? LOW : HIGH;  
141:    // Delays allow the ESP8266 to perform critical tasks  
142:    // defined outside of the sketch. These tasks include  
143:    // setting up, and maintaining, a WiFi connection.  
144:    delay(100);  
145:    // Potentially infinite loops are generally dangerous.  
146:    // Add delays -- allowing the processor to perform other  
147:    // tasks -- wherever possible.  
148:   }  
149:   Serial.println("WiFi connected");  
150:   Serial.println("IP address: ");  
151:   Serial.println(WiFi.localIP());  
152:  }  
153:  void initHardware()  
154:  {  
155:   Serial.begin(57600);  
156:   pinMode(DIGITAL_PIN, INPUT_PULLUP); // Setup an input to read  
157:   pinMode(LED_PIN, OUTPUT); // Set LED as output  
158:   digitalWrite(LED_PIN, HIGH); // LED off  
159:   // Don't need to set ANALOG_PIN as input,  
160:   // that's all it can be.  
161:  }  
162:  int postToPhant()  
163:  {  
164:   // LED turns on when we enter, it'll go off when we  
165:   // successfully post.  
166:   digitalWrite(LED_PIN, LOW);  
167:  // Retrieve the data from the device:  
168:   unsigned int data0, data1;  
169:   double lux;  // Resulting lux value  
170:   boolean good; // True if neither sensor is saturated  
171:   if (light.getData(data0,data1))  
172:   {  
173:    // getData() returned true, communication was successful  
174:    Serial.print("data0: ");  
175:    Serial.print(data0);  
176:    Serial.print(" data1: ");  
177:    Serial.print(data1);  
178:    // To calculate lux, pass all your settings and readings  
179:    // to the getLux() function.  
180:    // The getLux() function will return 1 if the calculation  
181:    // was successful, or 0 if one or both of the sensors was  
182:    // saturated (too much light). If this happens, you can  
183:    // reduce the integration time and/or gain.  
184:    // Perform lux calculation:  
185:    good = light.getLux(gain,ms,data0,data1,lux);  
186:    // Print out the results:  
187:    Serial.print(" lux: ");  
188:    Serial.print(lux);  
189:    if (good) Serial.println(" (good)"); else Serial.println(" (BAD)");  
190:   }  
191:   else  
192:   {  
193:    // getData() returned false because of an I2C error, inform the user.  
194:    byte error = light.getError();  
195:    printError(error);  
196:   }  
197:   // Declare an object from the Phant library - phant  
198:   Phant phant(PhantHost, PublicKey, PrivateKey);  
199:   // Add the three field/value pairs defined by our stream:  
200:   phant.add("temp_f", mySensor.readTempF());  
201:   phant.add("humidity", mySensor.readFloatHumidity());  
202:   phant.add("pressure_kpa", mySensor.readFloatPressure()/1000);  
203:   phant.add("lux", lux);  
204:   // Now connect to data.sparkfun.com, and post our data:  
205:   WiFiClient client;  
206:   const int httpPort = 80;  
207:   if (!client.connect(PhantHost, httpPort))  
208:   {  
209:    // If we fail to connect, return 0.  
210:    return 0;  
211:   }  
212:   // If we successfully connected, print our Phant post:  
213:   client.print(phant.post());  
214:   // Read all the lines of the reply from server and print them to Serial  
215:   while(client.available()){  
216:    String line = client.readStringUntil('\r');  
217:    //Serial.print(line); // Trying to avoid using serial  
218:   }  
219:   //Print each row in the loop  
220:   //Start with temperature, as that data is needed for accurate compensation.  
221:   //Reading the temperature updates the compensators of the other functions  
222:   //in the background.  
223:   Serial.print(mySensor.readTempC(), 2);  
224:   Serial.print(",");  
225:   Serial.print(mySensor.readTempF(), 3);  
226:   Serial.print(",");  
227:   Serial.print(mySensor.readFloatPressure(), 0);  
228:   Serial.print(",");  
229:   Serial.print(mySensor.readFloatAltitudeMeters(), 3);  
230:   Serial.print(",");  
231:   Serial.print(mySensor.readFloatAltitudeFeet(), 3);  
232:   Serial.print(",");  
233:   Serial.print(mySensor.readFloatHumidity(), 0);  
234:   Serial.print(",");  
235:   Serial.print(lux);  
236:   Serial.println();  
237:   // Before we exit, turn the LED off.  
238:   digitalWrite(LED_PIN, HIGH);  
239:   return 1; // Return success  
240:  }  
241:  void printError(byte error)  
242:   // If there's an I2C error, this function will  
243:   // print out an explanation.  
244:  {  
245:   Serial.print("I2C error: ");  
246:   Serial.print(error,DEC);  
247:   Serial.print(", ");  
248:   switch(error)  
249:   {  
250:    case 0:  
251:     Serial.println("success");  
252:     break;  
253:    case 1:  
254:     Serial.println("data too long for transmit buffer");  
255:     break;  
256:    case 2:  
257:     Serial.println("received NACK on address (disconnected?)");  
258:     break;  
259:    case 3:  
260:     Serial.println("received NACK on data");  
261:     break;  
262:    case 4:  
263:     Serial.println("other error");  
264:     break;  
265:    default:  
266:     Serial.println("unknown error");  
267:   }  
268:  }