· 7 years ago · Feb 19, 2018, 03:04 AM
1Sketch uses 23824 bytes (77%) of program storage space. Maximum is 30720 bytes.
2Global variables use 1870 bytes (91%) of dynamic memory, leaving 178 bytes for local variables. Maximum is 2048 bytes.
3Low memory available, stability problems may occur.
4
5#include "DHTesp.h"
6//#include <SPI.h>
7#include <UIPEthernet.h>
8
9DHTesp dhtA;
10//DHTesp dhtB;
11//DHTesp dhtC;
12//DHTesp dhtD;
13//DHTesp dhtE;
14//DHTesp dhtF;
15//DHTesp dhtG;
16//DHTesp dhtH;
17
18
19const int ledPin = LED_BUILTIN;
20int ledState = LOW;
21
22int interval = 10; // this is the number of seconds between reads (120=2mins)
23int numReads = 5; // Number of reads between posting to google docs.
24int multFact = 10; // multiplication factor 10 = 1 dec. place 100 = 2 dec places
25
26byte mac[] = {0xBE, 0xEF, 0xDE, 0xAD, 0xDE, 0xAD }; //Ethernet shield MAC. Andy's working {0xBE, 0xEF, 0xDE, 0xAD, 0xDE, 0xAD}
27byte ip[] = { 192,168,1,12 }; // Arduino device IP address
28char devid [] = "vCE3D036xxxxxxxx"; // Gsheets device ID from Pushingbox ('x's for privacy:)
29
30char server[] = "api.pushingbox.com";
31EthernetClient client;
32
33
34void setup()
35{
36 Serial.begin(9600);
37 Serial.println ("RESTART");
38
39 while (!Serial) {
40 ; // wait for serial port to connect. Needed for native USB port only
41 }
42
43 Serial.println("Trying to connect...");
44 if (Ethernet.begin(mac) == 0) {
45 Serial.println("Failed to configure Ethernet using DHCP");
46 // no point in carrying on, so do nothing forevermore:
47 while(true);
48 }
49 else{
50 Serial.print("OK, connected. Ethernet ready. ");
51 // print the Ethernet board/shield's IP address:
52 Serial.print("IP address: ");
53 Serial.println(Ethernet.localIP());
54 }
55
56 // give the Ethernet shield a second to initialize:
57 delay(1000);
58 Serial.println();
59 //Serial.println("A-StatttA-Temp (C)tA-humdid%tA-HeatI (C)tB-StatttB-Temp (C)tA-humdid%tB-HeatI (C)");
60 Serial.println("ttttt-Ath-Att-Bth-Btt-Cth-Ctt-Dth-Dtt-Eth-Ett-Fth-Ftt-Gth-Gtt-Hth-H");
61
62 //hey dB for some reason the Ethernet sheild uses pin D2 :( and pins 10,11,12,13
63 // https://arduinodiy.wordpress.com/2013/04/07/connect-an-enc28j60-ethernet-module-to-an-arduino/
64
65 // assign data pins
66 dhtA.setup(3);
67 //dhtB.setup(4);
68 //dhtC.setup(5);
69 //dhtD.setup(6);
70 //dhtE.setup(7);
71 //dhtF.setup(8);
72 //dhtG.setup(9);
73 //dhtH.setup(10); //watchout! i think Ethernet uses this pin too?
74 pinMode(ledPin, OUTPUT);
75
76 //end of void setup
77}
78
79
80void loop()
81{
82 int Ahumid = 0; int Atemp = 0;
83 int Bhumid = 0; int Btemp = 0;
84 int Chumid = 0; int Ctemp = 0;
85 int Dhumid = 0; int Dtemp = 0;
86 //int Ehumid = 0; int Etemp = 0;
87 //int Fhumid = 0; int Ftemp = 0;
88 //int Ghumid = 0; int Gtemp = 0;
89 //int Hhumid = 0; int Htemp = 0;
90
91 int j=0;
92 for (j = 1; j <= numReads ; j++ ) {
93
94 int p = 0;
95 for (p=1; p <= interval ; p++) {
96 delay (1000);
97 // swap the led state
98 if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; }
99 Serial.print (p); //show the seconds passing
100 Serial.print (",");
101 digitalWrite(ledPin, ledState);
102 }
103
104 Serial.print (" Reading");
105 Atemp += dhtA.getTemperature()*multFact; Ahumid += dhtA.getHumidity()*multFact;
106 //Btemp += dhtB.getTemperature()*multFact; Bhumid += dhtB.getHumidity()*multFact;
107 //Ctemp += dhtC.getTemperature()*multFact; Chumid += dhtC.getHumidity()*multFact;
108 //Dtemp += dhtD.getTemperature()*multFact; Dhumid += dhtD.getHumidity()*multFact;
109
110 // print the readings
111 //Serial.print(dhtA.getStatusString());
112 Serial.print("t"); Serial.print(Atemp);
113 Serial.print("t"); Serial.print(Ahumid);
114
115 Serial.print("t"); Serial.print(Btemp);
116 Serial.print("t"); Serial.print(Bhumid);
117
118 Serial.print("t"); Serial.print(Ctemp);
119 Serial.print("t"); Serial.print(Chumid);
120
121 Serial.print("t"); Serial.print(Dtemp);
122 Serial.print("t"); Serial.print(Dhumid);
123 Serial.println();
124 // and so here endeth 'j', the number of reads
125 }
126
127 Serial.print ("Avg...");
128 Atemp = Atemp/numReads; Ahumid = Ahumid/numReads;
129 Btemp = Btemp/numReads; Bhumid = Bhumid/numReads;
130 Ctemp = Ctemp/numReads; Chumid = Chumid/numReads;
131 Dtemp = Dtemp/numReads; Dhumid = Dhumid/numReads;
132
133 // print the averages so we can see what it is going to send
134 Serial.print("ttt");
135 Serial.print("t"); Serial.print(Atemp); Serial.print("t"); Serial.print(Ahumid);
136 Serial.print("t"); Serial.print(Btemp); Serial.print("t"); Serial.print(Bhumid);
137 Serial.print("t"); Serial.print(Ctemp); Serial.print("t"); Serial.print(Chumid);
138 Serial.print("t"); Serial.print(Dtemp); Serial.print("t"); Serial.print(Dhumid);
139 Serial.println();
140
141 Serial.print ("Prep for upload... ");
142 if (client.connect(server, 80))
143 {
144 Serial.print("Connected OK ... writing...");
145
146 client.print("GET /pushingbox?devid=");
147 client.print(devid);
148 client.print("&tempA="); client.print(Atemp);
149 client.print("&tempB="); client.print(Btemp);
150 client.print("&tempC="); client.print(Ctemp);
151 client.print("&tempD="); client.print(Dtemp);
152 client.print("&tempE=29&tempF=39&tempG=49&tempH=59");
153 //now humidity too
154 client.print("&humidA="); client.print(Ahumid);
155 client.print("&humidB="); client.print(Bhumid);
156 client.print("&humidC="); client.print(Chumid);
157 client.print("&humidD="); client.print(Dhumid);
158 client.print("&humidE=26&humidF=27&humidG=28&humidH=29");
159 client.print("&submit=Submit");
160 client.println(" HTTP/1.1");
161 client.println("Host: api.pushingbox.com");
162 client.println("Connection: close");
163 client.println();
164
165 Serial.println("written OK. & connection closed.");
166 Serial.println(); //Serial.println();
167
168 delay(1000); // maybe take this out to keep time stable?
169 client.stop();
170 }
171 else {
172 Serial.println("** NO CONNEX **"); Serial.println();
173 }
174
175//here endeth void loop
176}
177
178WARNING: library DHT_sensor_library_for_ESP32 claims to run on [esp32] architecture(s) and may be incompatible with your current board which runs on [avr] architecture(s).