Przeglądaj źródła

Changed to a new lib-function. This is the version that is used on Landet.

Thomas Chef 7 lat temu
rodzic
commit
aaae2e93eb
1 zmienionych plików z 23 dodań i 11 usunięć
  1. 23 11
      wifi_temp_logger.cpp

+ 23 - 11
wifi_temp_logger.cpp

@@ -47,7 +47,11 @@ void setup() {
  
 }
 
-float readTemperature() {
+// I found a new lib here:
+// https://github.com/milesburton/Arduino-Temperature-Control-Library
+// It looks complete and more advanced than this one that I use.
+
+double readTemperature() {
   byte i;
   byte present = 0;
   byte data[12];
@@ -62,12 +66,12 @@ float readTemperature() {
     Serial.println("Sensor not found");
     ds.reset_search();
     delay(250);
-    return 0.0;
+    return 11.6;
   }
 
   if (OneWire::crc8(addr, 7) != addr[7]) {
       Serial.println("CRC is not valid!");
-      return 0.0;
+      return 12.6;
   }
   Serial.println();
 
@@ -75,7 +79,7 @@ float readTemperature() {
   ds.select(addr);
   ds.write(0x44, 1);        // start conversion, with parasite power on at the end
   
-  delay(1000);     // maybe 750ms is enough, maybe not
+  delay(1200);     // maybe 750ms is enough, maybe not
   // we might do a ds.depower() here, but the reset will take care of it.
   
   present = ds.reset();
@@ -99,7 +103,7 @@ float readTemperature() {
   else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
   //// default is 12 bit resolution, 750 ms conversion time
 
-  celsius = (float)raw / 16.0;
+  celsius = (double)raw * 0.0625;
   Serial.print("  Temperature = ");
   Serial.print(celsius);
   Serial.println(" Celsius, ");
@@ -116,7 +120,7 @@ void waitUntilNextLoop() {
   delay(sleep);
 }
 
-void sendToCHEF_HTTPServer(float temperature)
+void sendToCHEF_HTTPServer(double temperature)
 {
     // Check for WiFi connection
     if((WiFiMulti.run() == WL_CONNECTED)) {
@@ -128,6 +132,9 @@ void sendToCHEF_HTTPServer(float temperature)
         // The target web page is: http://chef.suka.se/nashulta/report_nashulta_temp.php?outtemp=10.3
         String str = "http://chef.suka.se/nashulta/report_nashulta_temp.php?outtemp=";
         str += temperature;
+
+        Serial.println(str);
+
         http.begin(str);
 
         Serial.print("[HTTP] GET...\n");
@@ -160,26 +167,31 @@ void sendToCHEF_HTTPServer(float temperature)
 #define NO_OF_READS   12  // Send every two minutes
 
 void loop() {
-    static float totalTemp = 0;
+    static double totalTemp = 0.0;
     static uint16_t loopCnt = 0;
 
     Serial.println("------------------");
     Serial.print(millis());
     Serial.println(" ms");    
 
-    const float temp = readTemperature();
-
+    const double temp = readTemperature();
+    //sendToCHEF_HTTPServer( temp + 500 );
     totalTemp += temp;
-
     loopCnt++;
 
+    // When loopCnt ==  1,  1 read
+    // When loopCnt == 12, 12 reads
+
     // Calc mean lux and send to server.
     if( loopCnt == NO_OF_READS ) {
 
         totalTemp /= NO_OF_READS;
-        loopCnt = 0;
 
         sendToCHEF_HTTPServer( totalTemp );
+
+        // Reset
+        loopCnt = 0;
+        totalTemp = 0.0;
     }
 
     // Reset the device once every day, as an extra precaution