Monday, August 31, 2015

Cabin Fever Part 4: New Plans For How The Unit Will Work

In Part 3 of this "Cabin Fever" project, we were able to get a Temperature reading sent by email.

We realized that it was quite a lot of work for this little computer (technically a microcontroller) to send email. Now, we wanted it to receive emails too.

Revisiting the Original Plans
Our original plans were to:
1. Read a Temperature
2. send an email when the temperature was below some setpoint (like 32 degrees Fahrenheit which is the same as Zero degrees Centigrade, the freezing point of water).
3. Send an email every day with the past 24 temperatures that were read for each of the past 24 hours so we know that the unit is still working
4. Take a command from an email that tells the until to report temperature
5. Maybe, just maybe, also report when power failed

We have realized now that we need to simplify this a bit to allow it to fit into the small RAM memory (1K) on the Arduino Uno we are using.

New Plan
So, the new plan is as follows:
1. Read a Temperature
2. send an email (and copy the email address for the cell phone) when the temperature was below some setpoint (This will orignally be set to 40 degrees Fahrenheit because that is what was requested by the person I'm doing this for).
3. Send an email every week (and copy the email address for the cell phone) with the temperature so we know that the unit is still working
4. Take a command from an email that tells the until to report temperatures  (it will tell how often and how many times)
5. Forget about reporting when the power failed, it's just not practical at this time.

Detailed Requirements
This is what we decided when thinking about the details of the above:

1. When it starts up, it will send the temp once just to let you know it's working (and if it comes back from a power failure)
2. It will send the temp once a week just so you know it's still working
3. When it senses a temp below some setpoint (originally 40 degrees F) then it will send the temp.

It will work in 15 minute increments.
If the temp remains below the setupoint, it will send the temp every hour for the next 24 hours
Then it will send the temp only once a day.
(note: to use the email sending service on temboo that I selected, they only allow a certain number of free "calls" to their routines per month: 250, otherwise you need to pay )

Of course, if the temp goes above the setpoint, it will send one email to show the temp was above the setpoint , then it will stop sending emails again.

4. We can send an email to cause it to send some temps.
The subject of the email message must have the following characters, then it will send the temp according to the parameters:
CFRxx,yy
Where CF means "Cabin Fever" (the name I gave this project)
and
Where R means "Report"
and
where xx is the number of readings you want it sent (01 to 99)
and
where yy is a two digit number of the multiple of 15 minutes (01 to 99)
So, for example,  The following command:
CFR08,12
will cause it to send 8 temp readings that would each be 3 hours apart (12*15minutes)

5. If there is enough memory, I would also suggest we support a command to set the setpoint
CFTzz
where zz is a two digit setpoint temp in Fahrenheit

Issues with Oauth
In order to use Temboo to get gmail emails,we need to set up Oauth. You've probably seen it before, it's usually used when you allow a website to use your facebook or email login to login to some third party website. Oauth (Open Authorization) is used a lot for this. You can read more on it here on wikipedia and technical info here on the Oauth.net website.
This isn't all that complicated, there are instructions, but I ran into a problem that used up 3 to 4 hours because my temboo password had a backslash in it and that was causing issues with the temboo website. It took about a dozen emails  back and forth over 3 days with the temboo support staff to figure out that the password I had used was the issue.

New Issues with Temboo
Once I got past that obstacle, I started looking into the Temboo "choreo" that allowed me to get emails.  I realized that Temboo only allows 250 free "calls" per  month. I want the "Cabin Fever" unit to check for an email and when there is one, use the information in the email to tell the "Cabin Fever" unit how often to report temperatures.  Well, since checking for email is a "call" that counts toward the 250 free calls per month, that limits how often I can check for emails.   Using a little math:
24 hours / day X  30 days / Month  / 250 Calls /month =  2.88 hours/call.
So, we would only be able to check email every 2.88 hours. Not good.
We need a new solution.

IBM Bluemix and the Internet of Things Foundation
So, I am now looking into IBMs Internet of Things Foundation and Bluemix programming on the cloud.

An account for Bluemix is free for 30 days and I understand it's also free after that as long as you stay under certain limits.
So, I am following this tutorial and I'll be posting more info about this next.
"Build a cloud-ready temperature sensor with the Arduino Uno and the IBM IoT Foundation, Part 1: Build the circuit and set up the environment"

See part 5







Monday, August 24, 2015

Cabin Fever Part 3: Sending the Temperature Using Email


In the last installment of this project, I was able to send email.
This next part of the project is to send the temperature in an email.
The Hardware: Adding the sensor to the Shield
 I wondered if the Ethernet Shield would be using pin 2 where I had connected the temperature sensor in the first part of this project. I thought about reading up on the shield to find out, but then I decided to just try it.  So, I added the sensor to pin2, then I reloaded the first program and it worked! So, "all systems are go" from the hardware standpoint.
Running out of Memory
I quickly found out that I could run out of memory with the Arduino Uno. My program started doing weird things when I had long text strings to send (when I tried to send the temp in Centigrade and Fahrenheit with those words like I did in the first part of this project).  This used up a bit of the time to figure out too.
Simplify
So, I changed to having a very minimal program. I only sent the temperature.
I was able to send the temperature to two email addresses and to the email address for the cell phone so that it came to the cell phone as a SMS message!

What's Next?
So, then, since I decided to simplify, what would come next?  My original plans to do so much seemed too complex and out of reach with the memory constraints.  It was time to "go back to the drawing board."
What do you think would be a next step or a re-planing?
(see Part 4)


Monday, August 17, 2015

Cabin Fever Project Part 2: Sending Email


In the first part of this project, I was able to get the unit reading the temperature.
This second part of the project was be able to send email (so that I could send the temperature).

I spent about 5 or 6 hours total on this part of the project.

The Hardware
As you can see in the photo above, I was able to just plug the ethernet shield into the Arduino Uno board.  They just stacked on top of each other. There seems to be a clearance issue between the ethernet cable socket on the shield and the USB socket on the Uno below it, but I can put an insulator in there later. For now, I just made sure they were not touching; we don't need any electrical shorts now, do we?

Barking up the wrong tree (going down a path that led to nowhere)
The first 2 to 3 hours was spent following a few instructions I had found for using one technique to send emails (located here and here and here). But, after trying to get email working using this technique (an email SMTP server), I was not able to get it to work. It seems that finding an SMTP server that doesn't require encryption (SSL or TLS) isn't possible anymore. And, the Arduino isn't powerful enough to do encryption. Also, it appears that projects that used free services in the past (like twilio and SMTP2GO), no longer appear to be free to use (for some I seem to be able to set up a free account to test, but then have to pay to use it regularly).

Using a Service
So, I found this article about using a service called Temboo. It's free if you make less than a certain number of calls per month. I don't see us going over that number, but I can program it so that we don't.

Within a few hours of playing with this service (I was slowed by some technical issues of being logged out of the Temboo service), I was able to get it to send email from the Arduino.

 I also was able to send a text message (SMS) to a cell phone by sending an email to a specific email address for the phone carrier. Most carriers support this.


(Note: upon writing this, I also found some other means to send email. I may want to check these out:  sendgrid article (which talks about using node.js code instead of C for the Arduino) and this article which talks about using MongoDB for storing data)

So, now I have the email working. The next step is to connect part 1 of the project (Temperature) and Part 2 of the project (sending email) together so that I can send the temperature via email.

Stay tuned!
(see part 3)

Tuesday, August 11, 2015

Cabin Fever - A Temperature Sensor and Alert for A Cabin Away From Home

Part 1 of a multiple part story...

I wanted to help out someone I know by making a temperature sensor that would alert them if they were away from their cabin and the temperature went below freezing (which could cause the pipes to freeze). I through it would be fun to use the term "Cabin Fever" as the name of this project.

I started with an Arduino Uno Microcontroller. Arduino is open source hardware, so I have a clone.

There are three components to this project:
1. Temperature - we want to measure temperature
2. Email for notifications - we want to send a notification when the temperature is below a certain point (and, if possible, receive email so we can get commands to send a report or change the setpoint temperature)
3. Time - we want to record the time of when we get the temperature (we want to have an option of sending a report of past hourly temperatures with their corresponding time)

And, maybe (if possible) we might add a 4th component:  Sensing a power outage because this unit won't be too helpful if the power goes out too!

Parts to Buy:
  • Arduino Uno
  • Ethernet Shield (this allows the Uno to be connected to the internet to send and receive emails)
  • DS18B20 Temperature sensor
  • Power supply
  • Case to hold it all in
  • a few extra parts:  4.7K Ohm Resistor, Connecting wires

Here's how I tackled the project:
1. Temperature
I found a "sketch" (program) for the Arduino uno for the DS18B20 temperature sensor.  To connect the hardware, I looked at the diagram there. I found another article that helped me understand the pinout a bit better. I connected up the hardware and had it printing out the temperature through the serial monitor. You can see the three wires and resistor I connected in the photo above.

This worked really well and I had temperature readings working within and hour of starting!

Since the sensor reports in Centigrade, I did add some code to convert it to Fahrenheit.

 Serial.print(temperature);
  Serial.print(" Degrees C, ");
  temperature = (temperature * 9.0) /5.0 +32.0;
   Serial.print(temperature);
  Serial.println(" Degrees F");
 delay(1000); //just here to slow down the output so it is easier to read

Originally, I was getting the wrong conversion to Fahrenheit, so I found this article that taught me to use 9.0, 5.0, and 32.0 which fixed the conversion error.

Here's the output I'm getting:
24.69 Degrees C, 76.44 Degrees F
Our thermometer here says it's 75 degrees, so that's pretty close.

So, now I'm getting the temp readings.

My next task is to get the function working to send emails. That will be in my next post.






Monday, August 10, 2015

Treat People Well While They Are Still With Us

Recently we've had some people leave us : People have passed away (some seemed way too young), people have moved away, and people have left our employer and moved on.

One of these people passed away (at a relatively young age) just recently. At one point, she had posted on Facebook a story about a child in her family asking why we treat people so well after they're gone. He asked why we don't treat them well while they're with us.

This is a good question and something to think about. I'm trying to remember to treat people well while they are still with us. I'm learning to spend time with people now. I'm learning to encourage and compliment people now - while they are with us. 

The Bible says: "If possible, so far as it depends on you, live peaceably with all."  (Romans 12:18)
And "Do nothing from selfish ambition or conceit, but in humility count others more significant than yourselves." (Philippians 2:3).

What are your thoughts on this subject?