├── .travis.yml
├── README.md
├── embed_graph
└── graph.html
├── soil_sensor_carriots
└── soil_sensor_carriots.ino
└── soil_sensor_test
└── soil_sensor_test.ino
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 | before_install:
3 | - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
4 | - sleep 3
5 | - export DISPLAY=:1.0
6 | - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
7 | - tar xf arduino-1.6.5-linux64.tar.xz
8 | - sudo mv arduino-1.6.5 /usr/local/share/arduino
9 | - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
10 | install:
11 | - arduino --install-library "Adafruit CC3000 Library"
12 | - arduino --install-library "CC3000 MDNS"
13 | - arduino --install-library "aREST"
14 | script:
15 | - arduino --verify --board arduino:avr:uno $PWD/soil_sensor_carriots/soil_sensor_carriots.ino
16 | - arduino --verify --board arduino:avr:uno $PWD/soil_sensor_test/soil_sensor_test.ino
17 | notifications:
18 | email:
19 | on_success: change
20 | on_failure: change
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Wireless Gardening with Arduino & the CC3000 WiFi chip
2 | ==========================
3 |
4 | This is the code for the *Wireless Gardening with Arduino & the CC3000 WiFi chip* article on the Open Home Automation website. The article is about remotely measuring temperature & humidity with Arduino and the CC3000 WiFi chip and use it for gardening applications.
5 |
6 | You can find the article on the Open Home Automation website:
7 |
8 | http://www.openhomeautomation.net/wireless-gardening-arduino/
9 |
--------------------------------------------------------------------------------
/embed_graph/graph.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/soil_sensor_carriots/soil_sensor_carriots.ino:
--------------------------------------------------------------------------------
1 | /***************************************************
2 | This is a sketch to interface a soil sensor & Carriots
3 | using the Adafruit CC3000 breakout board (or WiFi shield)
4 |
5 | Written by Marco Schwartz for Open Home Automation
6 | ****************************************************/
7 |
8 | // Libraries
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include "utility/debug.h"
14 | #include "DHT.h"
15 | #include
16 | #include
17 |
18 | // Define CC3000 chip pins
19 | #define ADAFRUIT_CC3000_IRQ 3
20 | #define ADAFRUIT_CC3000_VBAT 5
21 | #define ADAFRUIT_CC3000_CS 10
22 |
23 | // Soil sensor pins
24 | const uint8_t dataPin = 6;
25 | const uint8_t clockPin = 7;
26 |
27 | // Soil sensor variables
28 | float t;
29 | float h;
30 | float dewpoint;
31 |
32 | // Create soil sensor object
33 | Sensirion soilSensor = Sensirion(dataPin, clockPin);
34 |
35 | // Create CC3000 instances
36 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
37 | SPI_CLOCK_DIV2); // you can change this clock speed
38 |
39 | // WLAN parameters
40 | #define WLAN_SSID "yourSSID"
41 | #define WLAN_PASS "yourPassword"
42 | // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
43 | #define WLAN_SECURITY WLAN_SEC_WPA2
44 |
45 | // Carriots parameters
46 | #define WEBSITE "api.carriots.com"
47 | #define API_KEY "yourApiKey"
48 | #define DEVICE "yourDeviceName@yourUserName"
49 |
50 | uint32_t ip;
51 |
52 | void setup(void)
53 | {
54 | // Initialize
55 | Serial.begin(115200);
56 |
57 | Serial.println(F("\nInitializing..."));
58 | if (!cc3000.begin())
59 | {
60 | Serial.println(F("Couldn't begin()! Check your wiring?"));
61 | while(1);
62 | }
63 |
64 | }
65 |
66 | void loop(void)
67 | {
68 | // Connect to WiFi network
69 | cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
70 | Serial.println(F("Connected!"));
71 |
72 | /* Wait for DHCP to complete */
73 | Serial.println(F("Request DHCP"));
74 | while (!cc3000.checkDHCP())
75 | {
76 | delay(100);
77 | }
78 |
79 | // Get the website IP & print it
80 | ip = 0;
81 | Serial.print(WEBSITE); Serial.print(F(" -> "));
82 | while (ip == 0) {
83 | if (! cc3000.getHostByName(WEBSITE, &ip)) {
84 | Serial.println(F("Couldn't resolve!"));
85 | }
86 | delay(500);
87 | }
88 | cc3000.printIPdotsRev(ip);
89 |
90 | // Get data & transform to integers
91 | soilSensor.measure(&t, &h, &dewpoint);
92 |
93 | // Convert data to String
94 | String temperature = doubleToString(t,2);
95 | String humidity = doubleToString(h,2);
96 |
97 | // Prepare JSON for Carriots & get length
98 | int length = 0;
99 |
100 | String data = "{\"protocol\":\"v2\",\"device\":\""+String(DEVICE)+"\",\"at\":\"now\",\"data\":{\"Temperature\":"+String(temperature)+",\"Humidity\":"+String(humidity)+"}}";
101 |
102 | length = data.length();
103 | Serial.print("Data length");
104 | Serial.println(length);
105 | Serial.println();
106 |
107 | // Print request for debug purposes
108 | Serial.println("POST /streams HTTP/1.1");
109 | Serial.println("Host: api.carriots.com");
110 | Serial.println("Accept: application/json");
111 | Serial.println("User-Agent: Arduino-Carriots");
112 | Serial.println("Content-Type: application/json");
113 | Serial.println("carriots.apikey: " + String(API_KEY));
114 | Serial.println("Content-Length: " + String(length));
115 | Serial.print("Connection: close");
116 | Serial.println();
117 | Serial.println(data);
118 |
119 | // Send request
120 | Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
121 | if (client.connected()) {
122 | Serial.println("Connected!");
123 | client.println("POST /streams HTTP/1.1");
124 | client.println("Host: api.carriots.com");
125 | client.println("Accept: application/json");
126 | client.println("User-Agent: Arduino-Carriots");
127 | client.println("Content-Type: application/json");
128 | client.println("carriots.apikey: " + String(API_KEY));
129 | client.println("Content-Length: " + String(length));
130 | client.println("Connection: close");
131 | client.println();
132 |
133 | client.println(data);
134 |
135 | } else {
136 | Serial.println(F("Connection failed"));
137 | return;
138 | }
139 |
140 | Serial.println(F("-------------------------------------"));
141 | while (client.connected()) {
142 | while (client.available()) {
143 | char c = client.read();
144 | Serial.print(c);
145 | }
146 | }
147 | client.close();
148 | Serial.println(F("-------------------------------------"));
149 |
150 | Serial.println(F("\n\nDisconnecting"));
151 | cc3000.disconnect();
152 |
153 | // Wait 10 seconds until next update
154 | delay(10000);
155 |
156 | }
157 |
158 | // Convert double to string
159 | String doubleToString(float input,int decimalPlaces){
160 | if(decimalPlaces!=0){
161 | String string = String((int)(input*pow(10,decimalPlaces)));
162 | if(abs(input)<1){
163 | if(input>0)
164 | string = "0"+string;
165 | else if(input<0)
166 | string = string.substring(0,1)+"0"+string.substring(1);
167 | }
168 | return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
169 | }
170 | else {
171 | return String((int)input);
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/soil_sensor_test/soil_sensor_test.ino:
--------------------------------------------------------------------------------
1 | /***************************************************
2 | This is a sketch to test the soil sensor based
3 | on the SHT10 temperature & humidity sensor
4 |
5 | Written by Marco Schwartz for Open Home Automation
6 | ****************************************************/
7 |
8 | // Include Sensirion library
9 | #include
10 |
11 | // Sensor pins
12 | const uint8_t dataPin = 6;
13 | const uint8_t clockPin = 7;
14 |
15 | // Variables for the temperature & humidity sensor
16 | float temperature;
17 | float humidity;
18 | float dewpoint;
19 |
20 | // Create sensor instance
21 | Sensirion soilSensor = Sensirion(dataPin, clockPin);
22 |
23 | void setup()
24 | {
25 | Serial.begin(115200);
26 | }
27 |
28 | void loop()
29 | {
30 | // Make a measurement
31 | soilSensor.measure(&temperature, &humidity, &dewpoint);
32 |
33 | // Print results
34 | Serial.print("Temperature: ");
35 | Serial.print(temperature);
36 | Serial.print(" C, Humidity: ");
37 | Serial.print(humidity);
38 | Serial.print(" %");
39 | Serial.println("");
40 |
41 | // Wait 100 ms before next measurement
42 | delay(100);
43 | }
44 |
--------------------------------------------------------------------------------