Randall Cole
Published © GPL3+

The Angry Humidor (Humidor Monitor)

This project takes hourly temperature and humidity readings from a humidor. A Web API sends the readings to Azure SQL and Twitter.

IntermediateShowcase (no instructions)16 hours4,408
The Angry Humidor (Humidor Monitor)

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
How cool is this little bugger?
×1
Humidity and Temperature Sensor
Adafruit Humidity and Temperature Sensor
Library worked great
×1
Humidor
×1

Software apps and online services

Microsoft Azure
Microsoft Azure

Story

Read more

Custom parts and enclosures

HTU21D-F Temperature + Humidity Sensor

Best Sensor for your humidor

Code

C# code to grab the values for the website.

C#
This C# code with collect the data from the humidor, send it to azure, and create a somewhat random tweet to send to twitter.
  public ActionResult Index(string name, string code, string temp, string humitiy)
        {
           
            if (code == "Security GUID") //not strong but something
            {

                string message = dao.daoWrite.Humidor(name, temp, humitiy); //Writes to AZURE
                
                ViewBag.Message = message;
                Random rnd = new Random();
                int number = rnd.Next(0, 100);
                //number = 1;

                if (number == 1)
                {
                    string[] person = { "human", "buffoon", "idiot", "simpleton", "clown", "meat sac"};
                    string[] owner = { "owner", "creator", "proprietor", "coder", "engineer", "proprietor", "coder", "engineer" };
                    string[] contact = { "Email", "Tweet", "Send a text to", "Send a smoke signal to", "Please call", "Contact" };

                    Random rndcontact = new Random();
                    Random rndperson = new Random();
                    
                    Random rndowner = new Random();
                    int randomcontact = rndcontact.Next(0,5);
                    int randomperson = rndperson.Next(0,5);
                    int randomowner = rndowner.Next(0,7);
                    

                    string tweet = (String.Format("{0} my {1} {2}, my temperature is {3} F and the humidity is {4} percent", contact[randomcontact], person[randomperson], owner[randomowner], temp, humitiy));
                    ViewBag.Message = tweet;
                    twitter.send(tweet);  // tweet away!
                  
                }
            }
            else
            {
                ViewBag.Message = "false";
            }


            return View();
        }

MKR1000 Code to collect and send the data to the website.

Arduino
I will update the code when I have time or a SSL post. This code will get you started with a simple get string.
#include <SPI.h>
#include <WiFi101.h>
#include "Adafruit_HTU21DF.h" 
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
char ssid[] = "SSID";      //  your network SSID (name) change this
char pass[] = "SSIDPasswordUrMomBhot";   //change this
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Initialize the Wifi client library
WiFiClient client;

// server address:
char server[] = "www.website.com"; //change this
//IPAddress server(64,131,82,241);

unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 3600L * 1000L; // delay between updates, in milliseconds

void setup() {
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);


 
  /*Initialize serial and wait for port to open:
 
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 */
if (!htu.begin()) {
//    Serial.println("Couldn't find sensor!");
    while (1);
  }
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
//    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
  //  Serial.print("Attempting to connect to SSID: ");
  //  Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    digitalWrite(6,HIGH);
delay(10000);
digitalWrite(6,LOW);
    
  }
  // you're connected now, so print out the status:
//  printWifiStatus();
}

void loop() {
 
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  
  while (client.available()) {
    char c = client.read();
        digitalWrite(6,HIGH);
  }
digitalWrite(6,LOW);

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }

}

// this method makes a HTTP connection to the server:
void httpRequest() {
float tempC = 0;
float tempF = 0;
tempC = htu.readTemperature();
tempF = (tempC * 1.8)+ 32;
float humi = htu.readHumidity();

if (humi < 68)
{
digitalWrite(7,HIGH);
}
else
{
 digitalWrite(7,LOW); 
}

  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, <port>)) //change this
  {
//   Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("GET /?name=H2&code=1&temp=");client.print(tempF);client.print("&humitiy=");client.print(humi);client.println(" HTTP/1.1");   
    client.println("Host: www.website.com:<port>"); //change this
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
   
    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
 // Serial.println("connection failed");
      digitalWrite(6,HIGH);
      delay(200);
      digitalWrite(6,LOW);
      delay(200);
      digitalWrite(6,HIGH);
      delay(200);
      digitalWrite(6,LOW);
      delay(200);
      digitalWrite(6,HIGH);
      delay(200);
      digitalWrite(6,LOW);
      delay(200);
  }
}


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(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Credits

Randall Cole

Randall Cole

1 project • 1 follower

Comments