updated positionFunction

updated positionFunction

--- SensorShirt/PositionFunctions.ino
+++ SensorShirt/PositionFunctions.ino
@@ -1,12 +1,14 @@
 /*
-  Position Functions
-  Kylie Dale and Michael Guida
-*/
+ * Position Functions
+ * Kylie Dale and Michael Guida
+ */
+
+// ------------------------ Right ------------------------

 boolean armAtSideRight() {
   if(backValue > (armSRBackVal - armSRBackTol) && backValue < (armSRBackVal + armSRBackTol)) {
-    if(shoulderValue > (armSRShoulderVal - armSRShoulderTol) && shoulderValue < (armSRShoulderVal + armSRShoulderTol)) {
-      if(underarmValue > (armSRUnderVal - armSRUnderTol) && underarmValue < (armSRUnderVal + armSRUnderTol) {
+    if(rShoulderValue > (armSRShoulderVal - armSRShoulderTol) && rShoulderValue < (armSRShoulderVal + armSRShoulderTol)) {
+      if(rUnderarmValue > (armSRUnderVal - armSRUnderTol) && rUnderarmValue < (armSRUnderVal + armSRUnderTol) {
         return true;
       }
     }
@@ -16,8 +18,8 @@

 boolean armSideRight45() {
   if(backValue > (armSR45BackVal - armSR45BackTol) && backValue < (armSR45BackVal + armSR45BackTol)) {
-    if(shoulderValue > (armSR45ShoulderVal - armSR45ShoulderTol) && shoulderValue < (armSR45ShoulderVal + armSR45ShoulderTol)) {
-      if(underarmValue > (armSR45UnderVal - armSR45UnderTol) && underarmValue < (armSR45UnderVal + armSR45UnderTol)) {
+    if(rShoulderValue > (armSR45ShoulderVal - armSR45ShoulderTol) && rShoulderValue < (armSR45ShoulderVal + armSR45ShoulderTol)) {
+      if(rUnderarmValue > (armSR45UnderVal - armSR45UnderTol) && rUnderarmValue < (armSR45UnderVal + armSR45UnderTol)) {
         return true;
       }
     }
@@ -27,8 +29,8 @@

 boolean armSideRight90() {
   if(backValue > (armSR90BackVal - armSR90BackTol) && backValue < (armSR90BackVal + armSR90BackTol)) {
-    if(shoulderValue > (armSR90ShoulderVal - armSR90ShoulderTol) && shoulderValue < (armSR90ShoulderVal + armSR90ShoulderTol)) {
-      if(underarmValue > (armSR90UnderVal - armSR90UnderTol) && underarmValue < (armSR90UnderVal + armSR90UnderTol)) {
+    if(rShoulderValue > (armSR90ShoulderVal - armSR90ShoulderTol) && rShoulderValue < (armSR90ShoulderVal + armSR90ShoulderTol)) {
+      if(rUnderarmValue > (armSR90UnderVal - armSR90UnderTol) && rUnderarmValue < (armSR90UnderVal + armSR90UnderTol)) {
         return true;
       }
     }
@@ -38,8 +40,8 @@

 boolean armSideRight135() {
   if(backValue > (armSR135BackVal - armSR135BackTol) && backValue < (armSR135BackVal + armSR135BackTol)) {
-    if(shoulderValue > (armSR135ShoulderVal - armSR135ShoulderTol) && shoulderValue < (armSR135ShoulderVal + armSR135ShoulderTol)) {
-      if(underarmValue > (armSR135UnderVal - armSR135UnderTol) && underarmValue < (armSR135UnderVal + armSR135UnderTol)) {
+    if(rShoulderValue > (armSR135ShoulderVal - armSR135ShoulderTol) && rShoulderValue < (armSR135ShoulderVal + armSR135ShoulderTol)) {
+      if(rUnderarmValue > (armSR135UnderVal - armSR135UnderTol) && rUnderarmValue < (armSR135UnderVal + armSR135UnderTol)) {
         return true;
       }
     }
@@ -49,8 +51,8 @@

 boolean armSideRight180() {
   if(backValue > (armSR180BackVal - armSR180BackTol) && backValue < (armSR180BackVal + armSR180BackTol)) {
-    if(shoulderValue > (armSR180ShoulderVal - armSR180ShoulderTol) && shoulderValue < (armSR180ShoulderVal + armSR180ShoulderTol)) {
-      if(underarmValue > (armSR180UnderVal - armSR180UnderTol) && underarmValue < (armSR180UnderVal + armSR180UnderTol)) {
+    if(rShoulderValue > (armSR180ShoulderVal - armSR180ShoulderTol) && rShoulderValue < (armSR180ShoulderVal + armSR180ShoulderTol)) {
+      if(rUnderarmValue > (armSR180UnderVal - armSR180UnderTol) && rUnderarmValue < (armSR180UnderVal + armSR180UnderTol)) {
         return true;
       }
     }
@@ -60,8 +62,8 @@

 boolean armFwdRight45() {
   if(backValue > (armFR45BackVal - armFR45BackTol) && backValue < (armFR45BackVal + armFR45BackTol)) {
-    if(shoulderValue > (armFR45ShoulderVal - armFR45ShoulderTol) && shoulderValue < (armFR45ShoulderVal + armFR45ShoulderTol)) {
-      if(underarmValue > (armFR45UnderVal - armFR45UnderTol) && underarmValue < (armFR45UnderVal + armFR45UnderTol)) {
+    if(rShoulderValue > (armFR45ShoulderVal - armFR45ShoulderTol) && rShoulderValue < (armFR45ShoulderVal + armFR45ShoulderTol)) {
+      if(rUnderarmValue > (armFR45UnderVal - armFR45UnderTol) && rUnderarmValue < (armFR45UnderVal + armFR45UnderTol)) {
         return true;
       }
     }
@@ -71,8 +73,8 @@

 boolean armFwdRight90() {
   if(backValue > (armFR90BackVal - armFR90BackTol) && backValue < (armFR90BackVal + armFR90BackTol)) {
-    if(shoulderValue > (armFR90ShoulderVal - armFR90ShoulderTol) && shoulderValue < (armFR90ShoulderVal + armFR90ShoulderTol)) {
-      if(underarmValue > (armFR90UnderVal - armFR90UnderTol) && underarmValue < (armFR90UnderVal + armFR90UnderTol)) {
+    if(rShoulderValue > (armFR90ShoulderVal - armFR90ShoulderTol) && rShoulderValue < (armFR90ShoulderVal + armFR90ShoulderTol)) {
+      if(rUnderarmValue > (armFR90UnderVal - armFR90UnderTol) && rUnderarmValue < (armFR90UnderVal + armFR90UnderTol)) {
         return true;
       }
     }
@@ -82,8 +84,8 @@

 boolean armFwdRight135() {
   if(backValue > (armFR135BackVal - armFR135BackTol) && backValue < (armFR135BackVal + armFR135BackTol)) {
-    if(shoulderValue > (armFR135ShoulderVal - armFR135ShoulderTol) && shoulderValue < (armFR135ShoulderVal + armFR135ShoulderTol)) {
-      if(underarmValue > (armFR135UnderVal - armFR135UnderTol) && underarmValue < (armFR135UnderVal + armFR135UnderTol)) {
+    if(rShoulderValue > (armFR135ShoulderVal - armFR135ShoulderTol) && rShoulderValue < (armFR135ShoulderVal + armFR135ShoulderTol)) {
+      if(rUnderarmValue > (armFR135UnderVal - armFR135UnderTol) && rUnderarmValue < (armFR135UnderVal + armFR135UnderTol)) {
         return true;
       }
     }
@@ -93,44 +95,147 @@

 boolean armFwdRight180() {
   if(backValue > (armFR180BackVal - armFR180BackTol) && backValue < (armFR180BackVal + armFR180BackTol)) {
-    if(shoulderValue > (armFR180ShoulderVal - armFR180ShoulderTol) && shoulderValue < (armFR180ShoulderVal + armFR180ShoulderTol)) {
-      if(underarmValue > (armFR180UnderVal - armFR180UnderTol) && underarmValue < (armFR180UnderVal + armFR180UnderTol)) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
+    if(rShoulderValue > (armFR180ShoulderVal - armFR180ShoulderTol) && rShoulderValue < (armFR180ShoulderVal + armFR180ShoulderTol)) {
+      if(rUnderarmValue > (armFR180UnderVal - armFR180UnderTol) && rUnderarmValue < (armFR180UnderVal + armFR180UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+// ------------------------- Left -------------------------
+
+boolean armAtSideLeft() {
+  if(backValue > (armSLBackVal - armSLBackTol) && backValue < (armSLBackVal + armSLBackTol)) {
+    if(lShoulderValue > (armSLShoulderVal - armSLShoulderTol) && lShoulderValue < (armSLShoulderVal + armSLShoulderTol)) {
+      if(lUnderarmValue > (armSLUnderVal - armSLUnderTol) && lUnderarmValue < (armSLUnderVal + armSLUnderTol) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideLeft45() {
+  if(backValue > (armSL45BackVal - armSL45BackTol) && backValue < (armSL45BackVal + armSL45BackTol)) {
+    if(lShoulderValue > (armSL45ShoulderVal - armSL45ShoulderTol) && lShoulderValue < (armSL45ShoulderVal + armSL45ShoulderTol)) {
+      if(lUnderarmValue > (armSL45UnderVal - armSL45UnderTol) && lUnderarmValue < (armSL45UnderVal + armSL45UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideLeft90() {
+  if(backValue > (armSL90BackVal - armSL90BackTol) && backValue < (armSL90BackVal + armSL90BackTol)) {
+    if(lShoulderValue > (armSL90ShoulderVal - armSL90ShoulderTol) && lShoulderValue < (armSL90ShoulderVal + armSL90ShoulderTol)) {
+      if(lUnderarmValue > (armSL90UnderVal - armSL90UnderTol) && lUnderarmValue < (armSL90UnderVal + armSL90UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideLeft135() {
+  if(backValue > (armSL135BackVal - armSL135BackTol) && backValue < (armSL135BackVal + armSL135BackTol)) {
+    if(lShoulderValue > (armSL135ShoulderVal - armSL135ShoulderTol) && lShoulderValue < (armSL135ShoulderVal + armSL135ShoulderTol)) {
+      if(lUnderarmValue > (armSL135UnderVal - armSL135UnderTol) && lUnderarmValue < (armSL135UnderVal + armSL135UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideLeft180() {
+  if(backValue > (armSL180BackVal - armSL180BackTol) && backValue < (armSL180BackVal + armSL180BackTol)) {
+    if(lShoulderValue > (armSL180ShoulderVal - armSL180ShoulderTol) && lShoulderValue < (armSL180ShoulderVal + armSL180ShoulderTol)) {
+      if(lUnderarmValue > (armSL180UnderVal - armSL180UnderTol) && lUnderarmValue < (armSL180UnderVal + armSL180UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armFwdLeft45() {
+  if(backValue > (armFL45BackVal - armFL45BackTol) && backValue < (armFL45BackVal + armFL45BackTol)) {
+    if(lShoulderValue > (armFL45ShoulderVal - armFL45ShoulderTol) && lShoulderValue < (armFL45ShoulderVal + armFL45ShoulderTol)) {
+      if(lUnderarmValue > (armFL45UnderVal - armFL45UnderTol) && lUnderarmValue < (armFL45UnderVal + armFL45UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armFwdLeft90() {
+  if(backValue > (armFL90BackVal - armFL90BackTol) && backValue < (armFL90BackVal + armFL90BackTol)) {
+    if(lShoulderValue > (armFL90ShoulderVal - armFL90ShoulderTol) && lShoulderValue < (armFL90ShoulderVal + armFL90ShoulderTol)) {
+      if(lUnderarmValue > (armFL90UnderVal - armFL90UnderTol) && lUnderarmValue < (armFL90UnderVal + armFL90UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armFwdLeft135() {
+  if(backValue > (armFL135BackVal - armFL135BackTol) && backValue < (armFL135BackVal + armFL135BackTol)) {
+    if(lShoulderValue > (armFL135ShoulderVal - armFL135ShoulderTol) && lShoulderValue < (armFL135ShoulderVal + armFL135ShoulderTol)) {
+      if(lUnderarmValue > (armFL135UnderVal - armFL135UnderTol) && lUnderarmValue < (armFL135UnderVal + armFL135UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armFwdLeft180() {
+  if(backValue > (armFL180BackVal - armFL180BackTol) && backValue < (armFL180BackVal + armFL180BackTol)) {
+    if(lShoulderValue > (armFL180ShoulderVal - armFL180ShoulderTol) && lShoulderValue < (armFL180ShoulderVal + armFL180ShoulderTol)) {
+      if(lUnderarmValue > (armFL180UnderVal - armFL180UnderTol) && lUnderarmValue < (armFL180UnderVal + armFL180UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+// ------------------------- Back -------------------------

 boolean backStraight() {
   if(backValue > (backStraightBackVal - backStraightBackTol) && backValue < (backStraightBackVal + backStraightBackTol)) {
-    if(shoulderValue > (backStraightShoulderVal - backStraightShoulderTol) && shoulderValue < (backStraightShoulderVal + backStraightShoulderTol)) {
-      if(underarmValue > (backStraightUnderVal - backStraightUnderTol) && underarmValue < (backStraightUnderVal + backStraightUnderTol)) {
-        return true;
-      }
-    }
+    //if(shoulderValue > (backStraightShoulderVal - backStraightShoulderTol) && shoulderValue < (backStraightShoulderVal + backStraightShoulderTol)) {
+      //if(underarmValue > (backStraightUnderVal - backStraightUnderTol) && underarmValue < (backStraightUnderVal + backStraightUnderTol)) {
+        return true;
+      //}
+    //}
   }
   return false;
 }

 boolean backBentFwd() {
   if(backValue > (backBentFBackVal - backBentFBackTol) && backValue < (backBentFBackVal + backBentFBackTol)) {
-    if(shoulderValue > (backBentFShoulderVal - backBentFShoulderTol) && shoulderValue < (backBentFShoulderVal + backBentFShoulderTol)) {
-      if(underarmValue > (backBentFUnderVal - backBentFUnderTol) && underarmValue < (backBentFUnderVal + backBentFUnderTol)) {
-        return true;
-      }
-    }
+    //if(shoulderValue > (backBentFShoulderVal - backBentFShoulderTol) && shoulderValue < (backBentFShoulderVal + backBentFShoulderTol)) {
+      //if(underarmValue > (backBentFUnderVal - backBentFUnderTol) && underarmValue < (backBentFUnderVal + backBentFUnderTol)) {
+        return true;
+      //}
+    //}
   }
   return false;
 }

 boolean backBentBack() {
   if(backValue > (backBentBBackVal - backBentBBackTol) && backValue < (backBentBBackVal + backBentBBackTol)) {
-    if(shoulderValue > (backBentBShoulderVal - backBentBShoulderTol) && shoulderValue < (backBentBShoulderVal + backBentBShoulderTol)) {
-      if(underarmValue > (backBentBUnderVal - backBentBUnderTol) && underarmValue < (backBentBUnderVal + backBentBUnderTol)) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
+    //if(shoulderValue > (backBentBShoulderVal - backBentBShoulderTol) && shoulderValue < (backBentBShoulderVal + backBentBShoulderTol)) {
+      //if(underarmValue > (backBentBUnderVal - backBentBUnderTol) && underarmValue < (backBentBUnderVal + backBentBUnderTol)) {
+        return true;
+      //}
+    //}
+  }
+  return false;
+}


Update blink.ino

Update blink.ino

--- examples/blink/blink.ino
+++ examples/blink/blink.ino
@@ -14,6 +14,7 @@

 void loop() {
   h.HSB(2000, 255, 255); //configure hsb
+  h.on(); //configure on
   h.set(1); //apply set hsb to lamp 1
   h.set(2); //apply set hsb to lamp 2


AP Access problem BugFix

AP Access problem BugFix

--- examples/Wifinfo/Wifinfo.ino
+++ examples/Wifinfo/Wifinfo.ino
@@ -475,6 +475,13 @@
       DebuglnF("Error!");
       Debugflush();

+      // STA+AP Mode without connected to STA, autoconnect will search
+      // other frequencies while trying to connect, this is causing issue
+      // to AP mode, so disconnect will avoid this
+
+      // Disable auto retry search channel
+      WiFi.disconnect();
+
       // SSID = hostname
       strcpy(ap_ssid, config.host );
       DebugF("Switching to AP ");


simplify according to http://www.tigoe.com/pcomp/code/arduinowiring/1161/


TODO-632: unit test

TODO-632: unit test

--- test_SECFRAME/test_SECFRAME.ino
+++ test_SECFRAME/test_SECFRAME.ino
@@ -296,7 +296,6 @@
   {
   Serial.println("FrameHeaderDecoding");
   OTRadioLink::SecurableFrameHeader sfh;
-//  uint8_t buf[OTRadioLink::SecurableFrameHeader::maxSmallFrameSize + 1];
   //
   // Test vector 1 / example from the spec.
   //Example insecure frame, valve unit 0% open, no call for heat/flags/stats.
@@ -324,6 +323,34 @@
   AssertIsEqual(1, sfh.getTl());
   AssertIsEqual(6, sfh.getBodyOffset());
   AssertIsEqual(8, sfh.getTrailerOffset());
+  //
+  // Test vector 2 / example from the spec.
+  //Example insecure frame, no valve, representative minimum stats {"b":1}
+  //In this case the frame sequence number is zero, and ID is 0x80 0x81.
+  //
+  //0e 4f 02 80 81 08 | 7f 11 7b 22 62 22 3a 31 | 61
+  //
+  //0e length of header (14) after length byte 5 + body 8 + trailer 1
+  //4f 'O' insecure OpenTRV basic frame
+  //02 0 sequence number, ID length 2
+  //80 ID byte 1
+  //81 ID byte 2
+  //08 body length 8
+  //7f no valve, no call for heat
+  //11 stats present flag only, unreported occupancy
+  //7b 22 62 22 3a 31  {"b":1  Stats: note that implicit trailing '}' is not sent.
+  //61 CRC value
+  const uint8_t buf2[] = { 0x0e, 0x4f, 0x02, 0x80, 0x81, 0x08, 0x7f, 0x11, 0x7b, 0x22, 0x62, 0x22, 0x3a, 0x31, 0x61 };
+  AssertIsEqual(6, sfh.checkAndDecodeSmallFrameHeader(buf2, sizeof(buf2)));
+  // Check decoded parameters.
+  AssertIsEqual(14, sfh.fl);
+  AssertIsEqual(2, sfh.getIl());
+  AssertIsEqual(0x80, sfh.id[0]);
+  AssertIsEqual(0x81, sfh.id[1]);
+  AssertIsEqual(8, sfh.bl);
+  AssertIsEqual(1, sfh.getTl());
+  AssertIsEqual(6, sfh.getBodyOffset());
+  AssertIsEqual(14, sfh.getTrailerOffset());
   }


temp and wind ranges

temp and wind ranges

--- exhaust_sensor_array.ino
+++ exhaust_sensor_array.ino
@@ -52,9 +52,9 @@
   log_file.print(',');
   log_file.print(map(NO,  0, 1023, 50, 10000)); //ppb
   log_file.print(',');
-  log_file.print(map(TEMP, 0, 1023 , 0, 0)); // TODO find temp range
+  log_file.print(map(TEMP, 0, 1023 , -40, 125)); // celsius
   log_file.print(',');
-  log_file.print(map(WIND, 0, 1023 , 0, 0)); // TODO find wind range
+  log_file.print(map(WIND, 0, 1023 , -40, 85)); // celsius
   log_file.println();
 }


Updated Network number to TTN official 0x13

--- examples/ttn-abp/ttn-abp.ino
+++ examples/ttn-abp/ttn-abp.ino
@@ -210,10 +210,10 @@
     uint8_t nwkskey[sizeof(NWKSKEY)];
     memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
     memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
-    LMIC_setSession (0x1, DEVADDR, nwkskey, appskey);
+    LMIC_setSession (0x13, DEVADDR, nwkskey, appskey);
     #else
     // If not running an AVR with PROGMEM, just use the arrays directly
-    LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
+    LMIC_setSession (0x13, DEVADDR, NWKSKEY, APPSKEY);
     #endif

     #if defined(CFG_eu868)


bugfixes

bugfixes

--- DRIVING/src/client/client.ino
+++ DRIVING/src/client/client.ino
@@ -55,7 +55,7 @@

 bool isValidInstruction(char *instruction){
   if(containsChar("RPS", *instruction) ||
-     isValidDebugConstruction(instruction) ||
+     isValidDebugInstruction(instruction) ||
      isValidMotorInstruction(instruction)){
     return true;
   }
@@ -79,11 +79,11 @@
   }
 }

-bool isValidMotorInstruction(){
+bool isValidMotorInstruction(char *instruction){
   if(*instruction == 'M'){
     ++instruction;
     if(containsChar("SP", *instruction)){
-      value = atoi(instruction);
+      int value = atoi(instruction);
       if(*instruction == 'S'){
 	return value < 255 && value > -255;
       }


Last stable version of Sim808 with UNO

Last stable version of Sim808 with UNO

--- test_configSIM808.ino
+++ test_configSIM808.ino
@@ -41,7 +41,7 @@

 // start reading from the first byte (address 0) of the EEPROM
 int addWrite = 0; //write
-
+int addRead = 0;  //position to read from EEPROM

 //The content of messages sent
 //#define MESSAGE  "hello,world"
@@ -102,6 +102,7 @@
 int posBuf;
 int seconds=0;
 int Powerkey=6;                 //Power pin for SIM808
+int DTRkey=8;                   //pin 8 of arduino will be connected to DTR of SIM808 pin (9)

 /*******************************************************************************************
@@ -124,7 +125,7 @@
   //delay(20000); //test to see if this reduce the drain of current of batery

   sim808_check_with_cmd("AT+CPOWD=1","OK\r\n",CMD);
-  //delay(5000);
+  delay(5000);
   pinMode(Powerkey, OUTPUT);   // initialize the digital pin as an output.
   power();                     // power on the sim808 or power down the sim808

@@ -142,17 +143,24 @@
 /*  if(sim808_wait_for_resp("SMS Ready\r\n", DATA, DEFAULT_TIMEOUT * 10, DEFAULT_INTERCHAR_TIMEOUT * 10)) {
     Serial.println("Call/SMS ready");
   }*/
+
+   /*****************************************************
+    * Enable charging
+    ****************************************************/
+    //sim808_send_cmd("AT+ECHARGE=1");
+

    /******************************************************
    * GPRS Configuration
    ******************************************************/
+  delay(5000);//try to save battery burst
   //GNSS power control
   sim808_check_with_cmd("AT+CGNSPWR=1","OK\r\n",CMD);
-  //delay(290);
+  delay(5000);

   //GNSS navitation, GEO-Fence and speed alarm URC report control
   sim808_check_with_cmd("AT+CGNSURC=0","OK\r\n",CMD);
-  //delay(300);
+  delay(5000);

   //GSM and GPRS configuration
   //check which network GPRS module is connected with
@@ -197,11 +205,41 @@
   ***********************************************************/
   connect_GPS(240, FIRST_TIME);  //wait GPS connect 2minutes

-  if(!GPSAnalyzer128()){
+  if(!GPSAnalyzer128()){ // Get current time from GPS
     setCurrentError(INITIAL_TIME_NOT_SET);
     printAllError();
-  }
-
+  }else{
+    addWrite = EEPROMReadInt(0);               //position 0 always have the last position to write data
+//    Serial.print("InitAdd: ");
+//    Serial.print(addWrite);
+    if(addWrite==0){
+      addWrite = addWrite + 2;                //Write date starting at position 2
+    }
+    addWrite = storeString(addWrite,"D");
+    addWrite = storeString(addWrite,startDateTime);
+    EEPROMWriteInt(0,addWrite);
+    Serial.println(startDateTime);
+  }
+
+
+/*****************************************************************************************
+ *Configure SIM808 to power save mode, AT+CSCLK.
+ *It can exit sleep mode  Configure SIM808
+ * Pull down DTR
+ * Receive voice or data call from network
+ * Receive SMS from network
+ * Receive external interrupt
+ * Charge VBUS pin
+ * AT+CSCLK=0 disable slow clock
+ *          1 enable slow clock controlled by DTR. when DTR=1 can enter sleep mode
+ *                                                 when DTR=0 exit sleep mode
+ *****************************************************************************************/
+  //configure DTR pin to normal HIGH
+  pinMode(DTRkey, OUTPUT);
+  digitalWrite(DTRkey, LOW);      //can not enter sleep mode
+
+  //sim808_check_with_cmd("AT+CSCLK=1\r\n","OK\r\n",CMD);  //activate the sleep mode
+
   GetGPSLocation();

   timerID = timer.setInterval(60000, GetGPSLocation); //call subroutine to GetGPSLocation every minute
@@ -232,7 +270,7 @@

   if ((readCurrentError(NO_GPRS_SIGNAL))== 1){
     timer.disable(timerID);
-    Serial.println("GetGPSDisabled");
+//    Serial.println("GetGPSDisabled");
     connect_GPS(120, RUNNING_TIME);                        //leave GPS ON/COLD START until timeout of 120 sec

     sim808_check_with_cmd("=0\r\AT+CGPSPWRn","OK\r\n",CMD);   //put GPS to sleep either acquire signal or not
@@ -242,7 +280,7 @@

     }else{                                                    //if GPRS_SIGNAL OK activate routine of getGPSLocation() again
       timer.enable(timerID);
-      Serial.println("GetGPSEnabled");
+//      Serial.println("GetGPSEnabled");
     }
   }

@@ -299,12 +337,9 @@
 //    }else{
 //      Serial.println("No valid # for SMS");
 //    }
-//  }
-
-
+//  }
+//  sim808_clean_buffer(gprsBuffer,32);

-//    sim808_clean_buffer(gprsBuffer,32);
-//  }

 }
@@ -457,8 +492,8 @@
       phone[sizeof(phone)-1] = '\0';

       //strcpy(gpsMode,token);
-      Serial.print("ph#: ");
-      Serial.println(phone);
+//      Serial.print("ph#: ");
+//      Serial.println(phone);
    }else return false;

    return true;
@@ -517,8 +552,8 @@

       //strcpy(gpsMode,token);
-      Serial.print("ph#: ");
-      Serial.println(phone);
+//      Serial.print("ph#: ");
+//      Serial.println(phone);
    }else return false;

    return true;
@@ -553,6 +588,18 @@
 }

 /****************************************************************************************
+ * DTR_low50ms()
+ * Function power on or power of SIM808.
+ ****************************************************************************************/
+void DTR_low50ms(void)
+{
+  digitalWrite(DTRkey, LOW);
+  delay(50);               // wait for 1 second
+  digitalWrite(DTRkey, HIGH);
+}
+
+
+/****************************************************************************************
  * powerGPS(int onOff)
  * This procedure power on GPS 1, power on and 0 power off.
  ****************************************************************************************/
@@ -575,10 +622,16 @@
 posBuf=0;
 int i = 0;
 int j=0;
-  Serial.println("***LOOP***");
+
+  digitalWrite(DTRkey, LOW);  //exit sleep mode
+  delay(50);                  //time to exit sleep mode
+
+  //sim808_send_cmd("AT+CFUN=1\r\n");
+
+  //Serial.println("*LOOP*");
   //readAllError();  //print all errors present in the previous loop

-//  //waking up GPS after sleep
+  //  //waking up GPS after sleep
   //if(!connect_GPS(25, RUNNING_TIME)){ //timeout of 25 seconds to acquire signal, 1h worst case lost 2x

   if(!connect_GPS(30, RUNNING_TIME)){ //timeout of 25 seconds to acquire signal, 1h worst case lost 2x
@@ -626,17 +679,29 @@

   //Send collected data to mysql server

+
+
   currentError = SendGPSLocation();  //error already saved inside the SendGPSLocation()
-  Serial.print("ERROR:");
-  Serial.println(currentError);
+
+  //Serial.print("ERROR:");
+  //Serial.println(currentError);
   //createSMSMessage(smsMessage,latitude, longitude, MSL_altitude, Speed);

   //put GPS to sleep
-  sim808_check_with_cmd("=0\r\AT+CGPSPWRn","OK\r\n",CMD);
+  sim808_check_with_cmd("AT+CGPSPWR=0\r\n","OK\r\n",CMD);
+
+  //test if make difference1
+  sim808_check_with_cmd("AT+CGNSPWR=0\r\n", "OK\r\n", CMD);
+
   //delay(5000);

   printAllError();
+
+  //sim808_send_cmd("AT+CFUN=4\r\n");
+  Serial.println("DTR high");
+  digitalWrite(DTRkey, HIGH); //can enter sleep mode
+

   return 0; //success

@@ -684,19 +749,34 @@
  ****************************************************************************/
  void printAllError(){
    byte i;
-
-   addWrite=storeString(addWrite,"L:");   //store letter 'L' of Loop to indicate init of one loop
-
-   Serial.println("ErrorList");
+   boolean first = true;
+   addWrite = EEPROMReadInt(0);               //position 0 always have the last position to write data
+   addWrite=storeString(addWrite,"L");   //store letter 'L' of Loop to indicate init of one loop
+
+
+   Serial.print("Alarm: ");
    for (i=1; i<ERROR_SIZE;i++){ //skipp the position 0 where only indicate there is fault no indication where
-    if(errorStatus[i]==1){
-      Serial.print(i);
-      Serial.print("==>");
-      Serial.println(errorStatus[i]);
-      //store EEPROM start write on address zero
-      addWrite=storeData(addWrite,i);
-    }
+     if(errorStatus[i]==1){
+       if(first){
+         first=false;
+       }else{
+         Serial.print(",");
+         addWrite=storeString(addWrite,",");
+       }
+       Serial.print(i);
+       addWrite=storeData(addWrite,i);
+     }
    }
+   Serial.println();
+   Serial.println();
+
+   addWrite=storeString(addWrite,"S");   //store letter 'S' GPRS signal to indicate level of signal 0-99
+   addWrite=EEPROMWriteInt(addWrite,currentRadioSig);
+
+   addWrite=storeString(addWrite,"G");              //store letter 'G' to indicate time to acquire signal from GPS after cold/hot start
+   addWrite=EEPROMWriteInt(addWrite,timeGetGPS);
+
+   EEPROMWriteInt(0,addWrite);          //Write last position of memory to write
  }

 ///****************************************************************************
@@ -726,8 +806,13 @@
   timerStart = millis();

   //sim808_flush_serial(); //test
-  Serial.println("WaitGPSsync");
+  Serial.print("GPSsync: ");
   sim808_check_with_cmd("AT\r\n","OK\r\n",CMD);
+
+  //test if make difference2
+  sim808_check_with_cmd("AT+CGNSPWR=1\r\n", "OK\r\n", CMD);
+  delay(1000);
+

   if(!sim808_check_with_cmd("AT+CGPSPWR=1\r\n","OK\r\n",CMD)){
     setCurrentError(POWER_GPS_FAIL);
@@ -771,10 +856,10 @@
       //sim808_flush_serial();
       clearCurrentError(NO_GPRS_SIGNAL);

-     Serial.print("GPSsync: ");
+     //Serial.print("GPSsync: ");
      timeGetGPS = ((unsigned long) (millis() - timerStart))/1000UL;
      Serial.println(timeGetGPS);
-     Serial.println((unsigned long) (millis() - timerStart));
+     //Serial.println((unsigned long) (millis() - timerStart));

       return true;
      }
@@ -806,7 +891,7 @@
 }//BASICALLY TO RESET THE BUFFER*/

 void PrintSecondsElapsed(){
-  Serial.print("*");
+//  Serial.print("*");
   //Serial.print("*Seconds: ");
   //Serial.println(seconds);
   seconds++;
@@ -827,12 +912,15 @@
 int SendGPSLocation(){
   char data2db[36]="0000.0000,00000.0000,00000.0,000.000"; //"latitude,longitude,MSL_altitude,Speed"
   byte error;
-  int signalStrenght;
+
   /************************************************************
    * CIPSTATUS result
    * 0 IP STATUS    ready to initiate connection
    * 8 CONNECT OK   ready to send data
    ************************************************************/
+
+
+
   //get signal strength, if < 7 not possible to send data to server
   sim808_clean_buffer(gprsBuffer,64);
   sim808_send_cmd("AT+CSQ\r\n");
@@ -873,13 +961,13 @@
       error = InitGPRS(RUNNING_TIME);   //errors already logged with setCurrentError(error) inside this InitGPRS
       previousRadioSig = currentRadioSig;
       if(error > 0) {                    //initGPRS failed
-        Serial.print("GPRSfail: ");
-        Serial.println(error);
+//        Serial.print("GPRSfail: ");
+//        Serial.println(error);

         return error;
       }
-      Serial.println("GprsInitOK");
+//      Serial.println("GprsInitOK");
     }
   }

@@ -1377,9 +1465,9 @@

    /* get the first token */
-   Serial.println("****************Content of gpsBuffer*******************");
-   Serial.println("valor do buffer :");
-   Serial.println(gprsBuffer);
+//   Serial.println("****************Content of gpsBuffer*******************");
+//   Serial.println("valor do buffer :");
+//   Serial.println(gprsBuffer);

    //Get Command sent AT_CGPSINF=128
    token = strtok(gprsBuffer,"\n\r" );
@@ -1431,8 +1519,8 @@
      return false;
    }

-   Serial.println("startDateTime:");
-   Serial.println(startDateTime);
+//   Serial.println("startDateTime:");
+//   Serial.println(startDateTime);
    return true;
 }

@@ -1473,8 +1561,8 @@

   addTemp = addTemp + 1;
   if (addTemp == EEPROM.length()) {
-    addTemp = 0;
-  }
+    addTemp = 2;                    //reserve address 0 and 1 to write last position
+   }
   return  addTemp;
  }

@@ -1497,7 +1585,7 @@
   addCurr=add;
   addNext = add + size;
   if (addNext >= EEPROM.length()) { //data do not fit EEPROM
-    addCurr = 0;
+    addCurr = 2;                     //address 0 and 1 is reserved for lastWriteAddress
     addNext = addCurr + size;
   }

@@ -1507,4 +1595,40 @@
   }
   return addNext;
 }
+
+/******************************************************************************
+ * Routines to write and read integer long 4 bytes max
+ * 32,767 hold 2^16 bits
+ * Needs 2 bytes
+ * ****************************************************************************/
+ unsigned int EEPROMWriteInt(int p_address, long p_value)
+  {
+  int addNext, addCurr;
+  byte lowByte0 = ((p_value >> 0) & 0xFF);
+  byte lowByte1 = ((p_value >> 8) & 0xFF);
+
+  addCurr=p_address;
+  addNext = p_address + 2;
+  if (addNext >= EEPROM.length()) { //data do not fit EEPROM
+    addCurr = 2;                     //address 0 and 1 is reserved for lastWriteAddress
+    addNext = addCurr + 2;
+  }
+
+  EEPROM.write(addCurr, lowByte0);
+  EEPROM.write(addCurr + 1, lowByte1);
+
+
+  return addNext;
+  }
+
+/******************************************************************************
+ * Routines to write and read integer long 4 bytes max
+ * 32,767 hold 2^16 bits
+ * Needs 2 bytes
+ * ****************************************************************************/
+unsigned int EEPROMReadInt(int p_address){
+  byte lowByte0 = EEPROM.read(p_address);
+  byte lowByte1 =  EEPROM.read(p_address + 1);
+  return ((lowByte0 << 0) & (0xFF)) + ((lowByte1 << 8) & (0xFF00));
+  }


Fixed comment

Fixed comment

--- examples/analog_bargraph/analog_bargraph.ino
+++ examples/analog_bargraph/analog_bargraph.ino
@@ -3,7 +3,7 @@
 #include <Atm_step.h>
 #include <Atm_comparator.h>

-// six leds on 3, 4, 5, 10, 11, 12 and a pot on A5
+// six leds on 4, 5, 6, 7, 8, 9 and a pot on A5

 Atm_comparator cmp;
 Atm_led led[6];


doc fix

doc fix

--- arduino/HandshakeInterface/HandshakeInterface.ino
+++ arduino/HandshakeInterface/HandshakeInterface.ino
@@ -18,12 +18,8 @@
 PANEL-SET 6 1 100 sculpture1
 PANEL-SET 6 2 100 sculpture1

-PANEL-SET 3 0 100 sculpture1 easein
-PANEL-SET 3 1 100 sculpture2 easein
-PANEL-SET 3 2 100 sculpture3 easein
-PANEL-SET 3 3 100 succedss easein
-PANEL-SET 3 4 100 error easein
-PANEL-SET 3 5 100 white easein
+PANEL-SET 3 0 100 rgb0
+PANEL-SET 3 1 100 rgb1

 */


Delete touchscreendemo.ino

Delete touchscreendemo.ino

--- examples/touchscreendemo/touchscreendemo.ino
+++ examples/touchscreendemo/touchscreendemo.ino
@@ -1,76 +0,0 @@
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License, or (at your option) any later version.
-//
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
-//
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#include <stdint.h>
-#include <TouchScreen.h>
-#include <TFT.h>
-#ifdef SEEEDUINO
-  #define YP A2   // must be an analog pin, use "An" notation!
-  #define XM A1   // must be an analog pin, use "An" notation!
-  #define YM 14   // can be a digital pin, this is A0
-  #define XP 17   // can be a digital pin, this is A3
-#endif
-
-#ifdef MEGA
-  #define YP A2   // must be an analog pin, use "An" notation!
-  #define XM A1   // must be an analog pin, use "An" notation!
-  #define YM 54   // can be a digital pin, this is A0
-  #define XP 57   // can be a digital pin, this is A3
-#endif
-
-//Measured ADC values for (0,0) and (210-1,320-1)
-//TS_MINX corresponds to ADC value when X = 0
-//TS_MINY corresponds to ADC value when Y = 0
-//TS_MAXX corresponds to ADC value when X = 240 -1
-//TS_MAXY corresponds to ADC value when Y = 320 -1
-
-#define TS_MINX 140
-#define TS_MAXX 900
-
-#define TS_MINY 120
-#define TS_MAXY 940
-
-
-// For better pressure precision, we need to know the resistance
-// between X+ and X- Use any multimeter to read it
-// The 2.8" TFT Touch shield has 300 ohms across the X plate
-TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
-
-void setup(void) {
-  Serial.begin(9600);
-}
-
-void loop(void) {
-  // a point object holds x y and z coordinates
-  Point p = ts.getPoint();
-
-  if (p.z > ts.pressureThreshhold) {
-     Serial.print("Raw X = "); Serial.print(p.x);
-     Serial.print("\tRaw Y = "); Serial.print(p.y);
-     Serial.print("\tPressure = "); Serial.println(p.z);
-  }
-
-
-  p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);
-  p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);
-
-  // we have some minimum pressure we consider 'valid'
-  // pressure of 0 means no pressing!
-  if (p.z > ts.pressureThreshhold) {
-     Serial.print("X = "); Serial.print(p.x);
-     Serial.print("\tY = "); Serial.print(p.y);
-     Serial.print("\tPressure = "); Serial.println(p.z);
-  }
-
-  delay(100);
-}


COH-78: WIP

COH-78: WIP

--- COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -3,7 +3,7 @@
 //#define CONFIG_REV9 // REV9 as CC1 relay, cut 2 of the board.

 // IF DEFINED: entire comms model switches to secure.
-//#define ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
+#define ENABLE_OTSECUREFRAME_ENCODING_SUPPORT

 #define DEBUG // Uncomment for debug output.

@@ -868,18 +868,22 @@
 // Assigns radio to PrimaryRadio alias.
 OTRadioLink::OTRadioLink &PrimaryRadio = RFM23B;

+// Quickly filter RX traffic to preserve queue space for stuff likely to be of interest.
 #if defined(ALLOW_CC1_SUPPORT_RELAY)
 // For a CC1 relay, ignore everything except FTp2_CC1PollAndCmd messages.
-// With care (not accessing EEPROM for example) this could also reject anything with wrong house code.
+// With care (not accessing EEPROM for example) this can also reject anything with wrong house code.
 static bool FilterRXISR(const volatile uint8_t *buf, volatile uint8_t &buflen)
   {
 #ifndef ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
   if((buflen < 8) || (OTRadioLink::FTp2_CC1PollAndCmd != buf[0])) { return(false); }
-  // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  // Filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  if((FHT8V.getHC1() == buf[1]) || (FHT8V.getHC2() == buf[2])) { return(false); }
 #else
-  // Expect secure frame with 2-byte ID and empty body.
-  if((buflen < 28) || ((0x80|OTRadioLink::FTp2_CC1PollAndCmd) != buf[0])) { return(false); }
-  // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  // Expect secure frame with 2-byte ID and 32-byte encrypted body.
+  if((buflen < 60) || ((0x80|OTRadioLink::FTp2_CC1PollAndCmd) != buf[0])) { return(false); }
+  // Filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  if((buf[1] & 0xf) < 2) { return(false); }
+  if((FHT8V.getHC1() == buf[2]) || (FHT8V.getHC2() == buf[3])) { return(false); }
 #endif // ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
   return(true); // Accept message.
   }
@@ -893,8 +897,8 @@
   if((OTRadioLink::FTp2_CC1Alert != t) && (OTRadioLink::FTp2_CC1PollResponse != t)) { return(false); }
   // TODO: filter for only associated relay address/housecodes.
 #else
-  // Expect secure frame with 2-byte ID and 32-byte encrypted body.
-  if(buflen < 60) { return(false); }
+  // Expect secure frame with 2-byte ID and empty or 32-byte encrypted body.
+  if(buflen < 28) { return(false); }
   const uint8_t t = buf[0];
   if(((0x80|OTRadioLink::FTp2_CC1Alert) != t) && ((0x80|OTRadioLink::FTp2_CC1PollResponse) != t)) { return(false); }
   // TODO: filter for only associated relay address/housecodes.


Fixed serial message processing

Fixed serial message processing

--- Code/Library/examples/Serial_Router/Serial_Router.ino
+++ Code/Library/examples/Serial_Router/Serial_Router.ino
@@ -126,7 +126,7 @@
 	  mesh.set_radio_listener(&ledTracing);
 #endif

-	serialMessageListeners[0] = (SerialMessageAdapter::SerialMessageListener*) &serialMessageAdapter;
+	serialMessageListeners[0] = (SerialMessageAdapter::SerialMessageListener*) &networkSerial;
 	serialMessageAdapter.setListeners(serialMessageListeners);

 	networkSerial.initSerial();
@@ -138,7 +138,7 @@

 //Receive RF messages
 void run_recv() {
-	last_message_processed = networkSerial.processOneMessage(&msg);
+	last_message_processed = serialMessageAdapter.processOneMessage(&msg);
 #if MW_BOARD_SELECT == MW_BOARD_MEGA
 	if ( last_message_processed != SerialMessageAdapter::SM_MESSAGE_NONE )
 		last_message_timestamp = RTT::millis();


better random for Lynch

better random for Lynch

--- first_one/first_one.ino
+++ first_one/first_one.ino
@@ -55,7 +55,7 @@
 unsigned int actualStep = 1;  // 1 - 5
 bool endCycle = false;
 bool lynchON = false;
-unsigned int lynchFlicks[] = { 33,66,99,101,109,111,123,256,333 };
+unsigned int lynchFlicks[] = { 33,66,99,101,106,109,123,132,161 };

 String message = encode( "PWNED " );

@@ -312,6 +312,7 @@
     }else{
       endCycle = true;
       lynchCounter = 1;
+      randomSeed(analogRead(1));
       int rr = random(0,9);
       waitLynch = lynchFlicks[rr]*timeMultiplier;
       LEDSOFF();


DHT22 Test - Temperatura y Humedad

DHT22 Test - Temperatura y Humedad

--- LM4F_E010/LM4F_E010.ino
+++ LM4F_E010/LM4F_E010.ino
@@ -11,8 +11,9 @@
  * Email:           mrchunckuee.psr@gmail.com
  * Description:     Este ejemplo se basa en la libreria de Adafruit para el
  *                  sensor de temperatura y humedad DHT22, cuando sepulsa SW1
- *                  envia los datos al monitor serial y realiza un blink en el
- *                  LED Azul, si se vuelve a pulsar SW1 el envio se detiene.
+ *                  la Stellaris envia los datos al monitor serial y realiza
+ *                  un blink en el LED Azul, si se vuelve a pulsar SW1 el
+ *                  envio se detiene y tambien el blink.
  *******************************************************************************
  * Rev.         Date            Comment
  *   v0.0.0     04/06/2019      Creación del firmware


Delete ampli_tie.ino

Delete ampli_tie.ino

--- ampli-tie/ampli_tie/ampli_tie.ino
+++ ampli-tie/ampli_tie/ampli_tie.ino
@@ -1,138 +0,0 @@
-/*
-LED VU meter for Arduino and Adafruit NeoPixel LEDs.
-
-Hardware requirements:
- - Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- - Adafruit Electret Microphone Amplifier (ID: 1063)
- - Adafruit Flora RGB Smart Pixels (ID: 1260)
-   OR
- - Adafruit NeoPixel Digital LED strip (ID: 1138)
- - Optional: battery for portable use (else power through USB or adapter)
-Software requirements:
- - Adafruit NeoPixel library
-
-Connections:
- - 3.3V to mic amp +
- - GND to mic amp -
- - Analog pin to microphone output (configurable below)
- - Digital pin to LED data input (configurable below)
- See notes in setup() regarding 5V vs. 3.3V boards - there may be an
- extra connection to make and one line of code to enable or disable.
-
-Written by Adafruit Industries.  Distributed under the BSD license.
-This paragraph must be included in any redistribution.
-*/
-
-#include <Adafruit_NeoPixel.h>
-
-#define N_PIXELS  16  // Number of pixels in strand
-#define MIC_PIN   A9  // Microphone is attached to this analog pin
-#define LED_PIN    6  // NeoPixel LED strand is connected to this pin
-#define DC_OFFSET  0  // DC offset in mic signal - if unusure, leave 0
-#define NOISE     10  // Noise/hum/interference in mic signal
-#define SAMPLES   60  // Length of buffer for dynamic level adjustment
-#define TOP       (N_PIXELS + 2) // Allow dot to go slightly off scale
-#define PEAK_FALL 40  // Rate of peak falling dot
-
-byte
-  peak      = 0,      // Used for falling dot
-  dotCount  = 0,      // Frame counter for delaying dot-falling speed
-  volCount  = 0;      // Frame counter for storing past volume data
-int
-  vol[SAMPLES],       // Collection of prior volume samples
-  lvl       = 10,      // Current "dampened" audio level
-  minLvlAvg = 0,      // For dynamic adjustment of graph low & high
-  maxLvlAvg = 512;
-Adafruit_NeoPixel
-  strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
-
-void setup() {
-
-  // This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
-  // Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
-  // line.  Audio samples are 'cleaner' at 3.3V.
-  // COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
-//  analogReference(EXTERNAL);
-
-  memset(vol, 0, sizeof(vol));
-  strip.begin();
-}
-
-void loop() {
-  uint8_t  i;
-  uint16_t minLvl, maxLvl;
-  int      n, height;
-
-
-
-  n   = analogRead(MIC_PIN);                        // Raw reading from mic
-  n   = abs(n - 512 - DC_OFFSET); // Center on zero
-  n   = (n <= NOISE) ? 0 : (n - NOISE);             // Remove noise/hum
-  lvl = ((lvl * 7) + n) >> 3;    // "Dampened" reading (else looks twitchy)
-
-  // Calculate bar height based on dynamic min/max levels (fixed point):
-  height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
-
-  if(height < 0L)       height = 0;      // Clip output
-  else if(height > TOP) height = TOP;
-  if(height > peak)     peak   = height; // Keep 'peak' dot at top
-
-
-  // Color pixels based on rainbow gradient
-  for(i=0; i<N_PIXELS; i++) {
-    if(i >= height)               strip.setPixelColor(i,   0,   0, 0);
-    else strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150)));
-
-  }
-
-
-
-  // Draw peak dot
-  if(peak > 0 && peak <= N_PIXELS-1) strip.setPixelColor(peak,Wheel(map(peak,0,strip.numPixels()-1,30,150)));
-
-   strip.show(); // Update strip
-
-// Every few frames, make the peak pixel drop by 1:
-
-    if(++dotCount >= PEAK_FALL) { //fall rate
-
-      if(peak > 0) peak--;
-      dotCount = 0;
-    }
-
-
-
-  vol[volCount] = n;                      // Save sample for dynamic leveling
-  if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
-
-  // Get volume range of prior frames
-  minLvl = maxLvl = vol[0];
-  for(i=1; i<SAMPLES; i++) {
-    if(vol[i] < minLvl)      minLvl = vol[i];
-    else if(vol[i] > maxLvl) maxLvl = vol[i];
-  }
-  // minLvl and maxLvl indicate the volume range over prior frames, used
-  // for vertically scaling the output graph (so it looks interesting
-  // regardless of volume level).  If they're too close together though
-  // (e.g. at very low volume levels) the graph becomes super coarse
-  // and 'jumpy'...so keep some minimum distance between them (this
-  // also lets the graph go to zero when no sound is playing):
-  if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
-  minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
-  maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
-
-}
-
-// Input a value 0 to 255 to get a color value.
-// The colors are a transition r - g - b - back to r.
-uint32_t Wheel(byte WheelPos) {
-  if(WheelPos < 85) {
-   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
-  } else if(WheelPos < 170) {
-   WheelPos -= 85;
-   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
-  } else {
-   WheelPos -= 170;
-   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
-  }
-}


Modified Volume down some more:

Modified Volume down some more:

--- arduino_signal/arduino_signal.ino
+++ arduino_signal/arduino_signal.ino
@@ -38,29 +38,29 @@
       case 121:
       Serial.write('3');
       SendVolUpCode();
-      delay(1);
+      delay(3);
       SendVolUpCode();
-      delay(1);
+      delay(2);
       SendVolUpCode();
-      delay(1);
+      delay(2);
       SendVolUpCode();
-      delay(1);
+      delay(2);
       SendVolUpCode();
-      delay(1);
+      delay(2);
       SendVolUpCode();
       break;
       case 122:
       Serial.write('4');
       SendVolDownCode();
-      delay(1);
+      delay(3);
       SendVolDownCode();
-      delay(1);
+      delay(2);
       SendVolDownCode();
-      delay(1);
+      delay(2);
       SendVolDownCode();
-      delay(1);
+      delay(2);
       SendVolDownCode();
-      delay(1);
+      delay(2);
       SendVolDownCode();
       break;
       case 123:
@@ -261,86 +261,83 @@
 void SendChannelDownCode() {

 //Change Channel Down
-delayMicroseconds(30044);
-pulseIR(8840);
-delayMicroseconds(4320);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(460);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(460);
-pulseIR(640);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(640);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(640);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(460);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(460);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(640);
-delayMicroseconds(460);
-pulseIR(640);
-delayMicroseconds(1560);
-pulseIR(640);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(640);
-delayMicroseconds(38900);
+delayMicroseconds(14308);
 pulseIR(8820);
-delayMicroseconds(2160);
-pulseIR(640);
-delayMicroseconds(28264);
-pulseIR(8860);
-delayMicroseconds(2120);
-pulseIR(620);
-delayMicroseconds(28304);
+delayMicroseconds(4360);
+pulseIR(580);
+delayMicroseconds(520);
+pulseIR(580);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(580);
+delayMicroseconds(520);
+pulseIR(580);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(580);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(520);
+delayMicroseconds(1660);
+pulseIR(600);
+delayMicroseconds(1600);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(560);
+delayMicroseconds(1640);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(580);
+delayMicroseconds(540);
+pulseIR(580);
+delayMicroseconds(1580);
+pulseIR(580);
+delayMicroseconds(540);
+pulseIR(580);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(560);
+delayMicroseconds(560);
+pulseIR(580);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(540);
+delayMicroseconds(560);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(560);
+delayMicroseconds(1620);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(38940);
 pulseIR(8820);
-delayMicroseconds(2160);
-pulseIR(640);
+delayMicroseconds(2180);
+pulseIR(580);
+delayMicroseconds(28324);
+pulseIR(8780);
+delayMicroseconds(2200);
+pulseIR(580);
+
 }

 void SendVolUpCode() {


move publish statement to be less frequent

--- controlBox.ino
+++ controlBox.ino
@@ -81,7 +81,6 @@
 		success = relayControl("off");
 	} else {
 		ThingSpeak.setField(1, boolToNum(pumpOn)); // our "pump on" field
-		Particle.publish(eventPrefix + "/waterTankPump/pumpOn", boolToText(pumpOn));
 	}
 }

@@ -97,6 +96,7 @@
 		ThingSpeak.writeFields(myWriteChannelNumber, myWriteAPIKey);
 		ThingSpeak.setField(2,0); // reset PIR motion sensor field to 'no motion detected'
 		lastMeasureTime = millis();
+		Particle.publish(eventPrefix + "/waterTankPump/pumpOn", boolToText(pumpOn));
 	}
 }


Poop McPoop

Poop McPoop

--- proj/ledvo_lounge_final/Animation_Base.ino
+++ proj/ledvo_lounge_final/Animation_Base.ino
@@ -8,11 +8,11 @@
     return (127 - in);
   }
   else if (in >= 128 && in < 192) {
-    return(in - 128);
+    return (in - 128);
   }
   else if (in >= 192) {
     return (255 - in);
-  }
+  }
 }

 // Reset everything aka set everything to black
@@ -114,6 +114,23 @@
   FastLED.show();
 }

+// Simple theater chase, but we mirrir it at every strip
+void theater_chase_mir(CPixelView<CRGB> leds, uint8_t numStrand, uint8_t pal_index) {
+  // First fill the template strand
+  fill_palette(led_tmplt, led_strand, pal_index, 6, gPalette, gBrightness, gBlending);
+
+  // Now fill the input led array with the template, alternating at every strand
+  for (uint8_t ss = 0; ss < numStrand; ss++) {
+    if (ss % 2 == 0) {
+      leds(ss * led_strand, (ss + 1)*led_strand - 1) = led_tmplt;
+    }
+    else {
+      leds(ss * led_strand, (ss + 1)*led_strand - 1) = led_tmplt(led_strand - 1, 0);
+    }
+  }
+
+}
+
 // A theater chase where packets switch direction every once in a while. Lets see how
 // this looks with a saw wave
 void theater_chase_tri(CRGB *leds, uint16_t numLED, uint8_t pal_index) {


Spark Core: Add EEPROM for user settings

Signed-off-by: Greg Meiste <8a8f45e57c045ec63dc7e56e5eda862ea8c7cd4f@gmail.com>

--- hw/spark/temp-alarm.ino
+++ hw/spark/temp-alarm.ino
@@ -28,7 +28,19 @@
 #define LED_PIN            D7

 #define SENSOR_CHECK_MS    2000
-#define SENSOR_REPORT_MS   30000
+
+#define EEPROM_PROGRAM_KEY 0xA5A5A5A5
+#define EEPROM_REPORT_MS   60000
+
+struct settingsEEPROM {
+    unsigned int programmedKey;
+    unsigned int sensorReportMillis;
+};
+
+union {
+    settingsEEPROM settings;
+    char raw[sizeof(settingsEEPROM)];
+} EEPROM_Data;

 double currentTempF = 0.0;
 double currentHumid = 0.0;
@@ -39,12 +51,30 @@

 DHT dht(DHT_PIN, DHT_TYPE);

-void buttonPress() {
+static void readEEPROM(void) {
+    unsigned int i;
+    for (i = 0; i < sizeof(settingsEEPROM); ++i) {
+        EEPROM_Data.raw[i] = EEPROM.read(i);
+    }
+    SERIAL.print(i);
+    SERIAL.println(" bytes read from EEPROM");
+}
+
+static void writeEEPROM(void) {
+    unsigned int i;
+    for (i = 0; i < sizeof(settingsEEPROM); ++i) {
+        EEPROM.write(i, EEPROM_Data.raw[i]);
+    }
+    SERIAL.print(i);
+    SERIAL.println(" bytes wrote to EEPROM");
+}
+
+static void buttonPress(void) {
     buttonPressMillis = millis();
     buttonReleaseMillis = 0;
 }

-void checkStateChange() {
+static void checkStateChange(void) {
     if (buttonPressMillis > 0) {
         if (digitalRead(BUTTON_PIN) == HIGH) {
             // False button press, ignore.
@@ -74,7 +104,7 @@
     }
 }

-void doMonitorIfTime() {
+static void doMonitorIfTime(void) {
     static unsigned long lastReadingMillis = 0;
     unsigned long now = millis();

@@ -103,13 +133,13 @@
     }
 }

-void doReportIfTime() {
+static void doReportIfTime(void) {
     static bool firstTime = true;
     static unsigned long lastReportMillis = 0;
     unsigned long now = millis();
     char publishString[64];

-    if (firstTime || ((now - lastReportMillis) >= SENSOR_REPORT_MS)) {
+    if (firstTime || ((now - lastReportMillis) >= EEPROM_Data.settings.sensorReportMillis)) {
         SERIAL.println("Reporting sensor data to server");

         snprintf(publishString, sizeof(publishString), "{\"tempF\": %.1f, \"humid\": %.1f}", currentTempF, currentHumid);
@@ -120,12 +150,23 @@
     }
 }

-void setup() {
+void setup(void) {
     SERIAL.begin(SERIAL_BAUD);

     SERIAL.println("Initializing DHT22 sensor");
     dht.begin();
     delay(2000);
+
+    readEEPROM();
+    if (EEPROM_PROGRAM_KEY == EEPROM_Data.settings.programmedKey) {
+        SERIAL.print("sensorReportMillis = ");
+        SERIAL.println(EEPROM_Data.settings.sensorReportMillis);
+    } else {
+        SERIAL.println("EEPROM not programmed! Setting default values.");
+        EEPROM_Data.settings.programmedKey = EEPROM_PROGRAM_KEY;
+        EEPROM_Data.settings.sensorReportMillis = EEPROM_REPORT_MS;
+        writeEEPROM();
+    }

     pinMode(LED_PIN, OUTPUT);

@@ -136,7 +177,7 @@
     Spark.variable("currentHumid", &currentHumid, DOUBLE);
 }

-void loop() {
+void loop(void) {
     checkStateChange();

     if (isReporting) {


adjusting rpm decay

adjusting rpm decay

--- arduino/car_control/src/main_control_nano/main_control_nano.ino
+++ arduino/car_control/src/main_control_nano/main_control_nano.ino
@@ -318,13 +318,12 @@
   write_rpms();

   //decay rpms incase vehicle has stopped
-  if (rpm_decay >=2){
-    rpm_decay = int(rpm_decay/2);
-    if (rpm_decay < 2){
-      rpm = 0;
-      commander.sendBinCmd(cmd_rpm, rpm);
-     }
-  }
+  rpm_decay++;
+  if (rpm_decay >100){
+    rpm = 0;
+    rpm_decay = 0;
+    commander.sendBinCmd(cmd_rpm, rpm);
+   }

@@ -378,7 +377,7 @@
 void write_rpms(){
   if (half_revolutions >= 2) {
      rpm = 30 * 1000/(millis() - timeold) * half_revolutions;
-     rpm_decay = rpm;
+     rpm_decay = 0;
      timeold = millis();
      half_revolutions = 0;
      commander.sendBinCmd(cmd_rpm, rpm);


MQTT GATEWAY

MQTT GATEWAY

Correct unsigned long for lumi value

--- MQTT_Gateway_MegaOSH/MQTT_Gateway_MegaOSH.ino
+++ MQTT_Gateway_MegaOSH/MQTT_Gateway_MegaOSH.ino
@@ -381,7 +381,10 @@
       if (myPacket.type == 10) {
         // Lumens
         if(MQTT_client.connected()) {
-          itoa((unsigned long)myPacket.dataF, buff_message, 10);
+          buff_S = String((unsigned int)myPacket.dataF);
+          buff_S.toCharArray(buff_message,20);
+
+          //itoa((unsigned long)myPacket.dataF, buff_message, 10);
           MQTT_client.publish("node/03/lumi/00", buff_message);
         }
       }
@@ -538,4 +541,4 @@
   extern int __heap_start, *__brkval;
   int v;
   return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
-}
+}


compare AC mode

compare AC mode

--- _68-acir-for-bedroom/_68-acir-for-bedroom.ino
+++ _68-acir-for-bedroom/_68-acir-for-bedroom.ino
@@ -125,10 +125,13 @@
   {
     if (root.containsKey("AC"))
     {
-      ir_data.ac_mode = root["AC"];
-      if (bpresence)
+      if (ir_data.ac_mode != root["AC"])
       {
-        ir_data.haveData = true;
+        ir_data.ac_mode = root["AC"];
+        if (bpresence)
+        {
+          ir_data.haveData = true;
+        }
       }
     }
   }
@@ -140,6 +143,7 @@
      if (ir_data.ac_temp != root["ac_temp"])
      {
         ir_data.ac_temp = root["ac_temp"];
+
         /*
             if (root.containsKey("ac_flow"))
             {
@@ -304,6 +308,7 @@
     delay(10);
     WiFi.mode(WIFI_STA);
     WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
+    WiFi.hostname("esp-irbedroom");

     int Attempt = 0;
     while (WiFi.status() != WL_CONNECTED)


Updated link to software SPI library

Updated link to software SPI library

--- examples/Settings/Settings.ino
+++ examples/Settings/Settings.ino
@@ -51,13 +51,14 @@

 // to use non-default SPI interface or software SPI
 // implementation, pass the SPI interface to the LoRa
-// constructor
+// constructor - this interface must be compatible
+// with Arduino SPIClass!
 //
-// DigitalIO library for software SPI
-// https://github.com/greiman/DigitalIO
-//#include "DigitalIO.h"
-//SoftSPI<MISO_PIN, MOSI_PIN, SCK_PIN> softSpi;
-//SX1278 softLora = new LoRa(2, 3, 10, softSpi);
+// Software SPI library
+// https://github.com/MajenkoLibraries/SoftSPI
+//#include "SoftSPI.h"
+//SoftSPI mySPI(4, 5, 6) ;
+//SX1278 softLora = new LoRa(2, 3, 10, mySPI);

 void setup() {
   Serial.begin(9600);


Added real on/off for PID, and testing out the zeroing of integral term on full/no PID output.

--- grill.ino
+++ grill.ino
@@ -9,7 +9,10 @@
 // Specify the links and initial tuning parameters
 double thermTemp, output, targetTemp;
 // recos for PID from heatermeter are 3, .1, 15
-PID pid(&thermTemp, &output, &targetTemp, 2, .1, 20, DIRECT);
+double P = 2.0;
+double I = 0.1;
+double D = 20;
+PID pid(&thermTemp, &output, &targetTemp, P, I, D, DIRECT);

 Display display(12, 11, 5, 4, 3, 2, &thermTemp, &targetTemp);
 Thermistor therm(A0, 2.4723753e-4, 2.3402251e-4, 1.3879768e-7, 10000);
@@ -19,7 +22,7 @@

 void setup() {
   // turn the PID on
-  pid.SetMode(AUTOMATIC);
+  // pid.SetMode(AUTOMATIC);
 }

 void loop() {
@@ -29,9 +32,20 @@
   display.update();

   if (pauseButton.isPaused() == true) {
+    if (pid.GetMode() != MANUAL) {
+      pid.SetMode(MANUAL);
+    }
     fan.powerTo(0);
     return;
   } else {
+    if (pid.GetMode() != AUTOMATIC) {
+      pid.SetMode(AUTOMATIC);
+    }
+    if ((output == 0 || output == 100) && pid.GetKi() !== 0) {
+      pid.SetTunings(P, 0, D);
+    } else if (pid.GetKi() !== I) {
+      pid.SetTunings(P, I, D);
+    }
     pid.Compute();
     fan.powerTo(output);
   }


small tweak for custom->observer

small tweak for custom->observer

--- examples/observer/observer.ino
+++ examples/observer/observer.ino
@@ -40,7 +40,8 @@
          info.advData[1] == GAP_ADTYPE_FLAGS &&
          info.advData[2] == (GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED) &&
          info.advData[3] == 0x03 &&
-         info.advData[4] == GAP_ADTYPE_MANUFACTURER_SPECIFIC)
+         info.advData[4] == GAP_ADTYPE_MANUFACTURER_SPECIFIC) &&
+         info.advData[5] == 0xAC
       {
          if(info.advData[6] == 0)
          {


Little tweak.

Little tweak.

--- alarm.ino
+++ alarm.ino
@@ -191,7 +191,7 @@
 }

 void setup() {
-  Serial.begin(9600);
+  // Serial.begin(9600);

   // Read the alarm struct from EEPROM storage.
   EEPROM_readAnything(EEPROM_ADDRESS, alarm);
@@ -306,7 +306,7 @@
     editTime.minute = dt.minute;
   }

-  tone(SPEAKER_PIN, 2000, 20);
+  tone(SPEAKER_PIN, ALARM_FREQ, 20);
   update(&context);
 }


Added explanation of LED_COLOUR_ORDER

Added explanation of LED_COLOUR_ORDER

--- TWANG.ino
+++ TWANG.ino
@@ -24,7 +24,7 @@
 #define NUM_LEDS             475
 #define DATA_PIN             3
 #define CLOCK_PIN            4
-#define LED_COLOR_ORDER      BGR//GBR
+#define LED_COLOR_ORDER      BGR   //if colours aren't working, try GRB or GBR
 #define BRIGHTNESS           150
 #define DIRECTION            1     // 0 = right to left, 1 = left to right
 #define MIN_REDRAW_INTERVAL  16    // Min redraw interval (ms) 33 = 30fps / 16 = 63fps


More robust version of Arduino sketch.

More robust version of Arduino sketch.

This implements a more comprehensive system for polling, downloading and finally printing an image. Once the polled URL has some content, it is downloaded, and the ready LED is lit. Pressing the button will then trigger printing.

This is as a result of some fairly exhaustive testing on different networks with a stripped down sketch. On my home network, downloads are completely reliable from both local and remote servers.

--- wee_printer.ino
+++ wee_printer.ino
@@ -2,24 +2,33 @@
 #include <Ethernet.h>
 #include <SD.h>

-/* Includes for printer */
 #include <SoftwareSerial.h>
 #include <Thermal.h>
+#include <Bounce.h>

+#ifdef DEBUG
 #define debug(a) Serial.print(millis()); Serial.print(": "); Serial.println(a);
 #define debug2(a, b) Serial.print(millis()); Serial.print(": "); Serial.print(a); Serial.println(b);
+#else
+#define debug(a)
+#define debug2(a, b)
+#endif

-const int greenPin = 6;
-const int redPin = 7;
+const int errorLED = 5;
+const int downloadLED = 6;
+const int readyLED = 7;

 void initDiagnosticLEDs() {
-  pinMode(greenPin, OUTPUT);
-  pinMode(redPin, OUTPUT);
-  digitalWrite(greenPin, HIGH);
-  digitalWrite(redPin, HIGH);
-  delay(100);
-  digitalWrite(greenPin, LOW);
-  digitalWrite(redPin, LOW);
+  pinMode(errorLED, OUTPUT);
+  pinMode(downloadLED, OUTPUT);
+  pinMode(readyLED, OUTPUT);
+  digitalWrite(errorLED, HIGH);
+  digitalWrite(downloadLED, HIGH);
+  digitalWrite(readyLED, HIGH);
+  delay(1000);
+  digitalWrite(errorLED, LOW);
+  digitalWrite(downloadLED, LOW);
+  digitalWrite(readyLED, LOW);
 }

 const int printer_RX_Pin = 2;  // this is the green wire
@@ -32,16 +41,13 @@
 }

 const int SD_Pin = 4;
-
 void initSD() {
-  // stop the SD stuff futzing.
   pinMode(SD_Pin, OUTPUT);
   SD.begin(SD_Pin);
 }

 byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x86, 0x67 }; //physical mac address
 EthernetClient client;
-
 void initNetwork() {
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
@@ -49,6 +55,7 @@
     // no point in carrying on, so do nothing forevermore:
     while(true);
   }
+  delay(1000);
   // print your local IP address:
   debug2("IP address: ", Ethernet.localIP());
 }
@@ -56,80 +63,107 @@
 void setup(){
   Serial.begin(9600);

-  initPrinter();
   initSD();
   initNetwork();
+  initPrinter();
   initDiagnosticLEDs();
 }

-const char* host = "192.168.1.22";
-const int port = 4567;
-const char *path = "/1";
+//const char* host = "192.168.1.22"; // uberatom
+//const char* host = "192.168.1.67"; // lazyatom
+//const char* host = "178.79.132.137"; // interblah
+const char* host = "interblah.net";
+const uint16_t port = 4567;
+const char *path = "/maybe";

-int failures = 0;
-int requests = 0;
+uint16_t failures = 0;
+uint16_t requests = 0;
+boolean downloadWaiting = false;
+char* cacheFilename = "TMP";

-void loop() {
-  digitalWrite(greenPin, LOW);
+void checkForDownload() {
+  uint32_t length = 0;
+  uint32_t content_length = 0;
+
+  if (SD.exists(cacheFilename)) SD.remove(cacheFilename);
+  File cache = SD.open(cacheFilename, FILE_WRITE);

   if (client.connect(host, port)) {
-    requests++;
-    uint32_t content_length = 0;
-
-    debug("Connected.");
+    digitalWrite(downloadLED, HIGH);
     client.print("GET "); client.print(path); client.println(" HTTP/1.0\n");
-    uint32_t length = 0;
-    if (SD.exists("TMP")) { SD.remove("TMP"); }
-    File cache = SD.open("TMP", FILE_WRITE);
-
+    boolean parsingHeader = true;
+    unsigned long start = millis();
     while(client.connected()) {
       debug("Still connected");
-      // the server will close the connection when it is finished sending packets
+      while(client.available()) {
+        if (parsingHeader) {
+          client.find("Content-Length: ");
+          char c;
+          while (isdigit(c = client.read())) {
+            content_length = content_length*10 + (c - '0');
+          }
+          debug2("Content length was: ", content_length);
+          client.find("\n\r\n"); // the first \r may already have been read above
+          parsingHeader = false;
+        } else {
+          cache.write(client.read());
+          length++;
+        }
+      }
+      debug("No more data to read at the moment...");
+    }

-      client.find("Content-Length: ");
-      char c;
-      while (isdigit(c = client.read())) {
-        content_length = content_length*10 + (c - '0');
-      }
-      client.find("\r\n\r\n");
-
-      debug2("Content length was: ", content_length);
-
-      debug("Now reading data");
-      while(client.available()) {
-        // ...but not until this buffer is empty
-        cache.write(client.read());
-        length++;
-      }
-      debug("Done reading for now...");
-    }
-    // close your end after the server closes its end
+    debug("Server has disconnected");
+    digitalWrite(downloadLED, LOW);
+    // Close the connection, and flush any unwritten bytes to the cache.
     client.stop();
+    cache.seek(0);
+    boolean success = (content_length == length) && (content_length == cache.size());
     cache.close();

-    cache = SD.open("TMP");
+    unsigned long duration = millis() - start;
+    debug2("Total bytes: ", length);
+    debug2("Duration: ", duration);
+    debug2("Speed: ", length/(duration/1000.0)); // NB - floating point math increases sketch size by ~2k

-    if (cache.size() != content_length) {
-      debug2("File size: ", cache.size());
+    if (success) {
+      if (content_length > 0) {
+        downloadWaiting = true;
+        digitalWrite(readyLED, HIGH);
+      }
+    } else {
       failures++;
-    } else {
-      digitalWrite(greenPin, HIGH);
-      if (content_length > 0) {
-        printer.printBitmap(&cache);
-        printer.feed(postPrintFeed);
-      }
+      debug2("Oh no, a failure: ", failures);
+      digitalWrite(errorLED, HIGH);
+      digitalWrite(downloadLED, HIGH);
     }
+  } else {
+    debug("Couldn't connect");
+    digitalWrite(errorLED, HIGH);
+  }
+}

-    cache.close();
+void printFromDownload() {
+  File cache = SD.open(cacheFilename);
+  printer.printBitmap(&cache);
+  printer.feed(postPrintFeed);
+  cache.close();
+}

-    if (failures > 0) {
-      digitalWrite(redPin, HIGH);
+const int buttonPin = 8;
+Bounce bouncer = Bounce(buttonPin, 5); // 5 millisecond debounce
+unsigned long pollingDelay = 10000; // 1 minute
+
+void loop() {
+  if (downloadWaiting) {
+    bouncer.update();
+    if (bouncer.read() == HIGH) {
+      printFromDownload();
+      downloadWaiting = false;
+      digitalWrite(readyLED, LOW);
     }
-    debug2("Total read: ", length);
-    Serial.print("Total failures: "); Serial.print(failures); Serial.print("/"); Serial.println(requests);
   } else {
-    debug("Couldn't connect.");
+    delay(pollingDelay);
+    checkForDownload();
   }
-
-  delay(1000);
-}
+}


Ajout de l'autoscroll

Ajout de l'autoscroll

--- arduino/CommunicationArduino/CommunicationArduino.ino
+++ arduino/CommunicationArduino/CommunicationArduino.ino
@@ -14,23 +14,10 @@

 void loop()
 {
-  /*if (Serial.available())  {
+  if (Serial.available())  {
     delay(100);
     lcd.clear();
     lcd.autoscroll();
     lcd.print(Serial.readString());
-  }*/
-  // when characters arrive over the serial port...
-  if (Serial.available()) {
-    // wait a bit for the entire message to arrive
-    delay(100);
-    // clear the screen
-    lcd.clear();
-    lcd.autoscroll();
-    // read all the available characters
-    while (Serial.available() > 0) {
-      // display each character to the LCD
-      lcd.write(Serial.read());
-    }
   }
 }


Moved all blocking code to print delay loop

--- Arduino/_firmware/_firmware.ino
+++ Arduino/_firmware/_firmware.ino
@@ -1,63 +1,99 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                           SENSOR NETWORK FIRMWARE
-
+//
 // This is the code for the sensor node. It integrates the following SENSORS an prints data to the serial monitor.
 // 1. Temperature Sensors.
 //      At various locations around the pump
-// 2. Tachometer
-//      Measuring the rpms of the
-// 3. Load Washers 1 & 2
-// 4. Level Sensor
-
+// 2. Shaft Temperature Sensor
+// 3. Tachometer
+//      Measuring the rpms of the motor shaft
+// 4. Load Washers 1 & 2
+// 5. Level Sensor
+//
 //The following are driven based on the sensor values:
 // 5. Solenoid Drain Valve
 // 6. The Serial Monitor
 //      The data from each sensor is printed on the serial monitor. The data on the serial monitor will be picked up
-//      by the Zigbee module and will be available on the baseNode
-
+//      by the Zigbee module and automatically transmitted to the base node. (Remember to toggle switch on shield to SERIAL)

 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                           1. TEMPERATURE SENSOR
+//                                            1. TEMPERATURE SENSORS
 #include <OneWire.h>
 #include <DallasTemperature.h>

-// Data wire is plugged into port 2 on the Arduino
-#define ONE_WIRE_BUS 4
-#define TEMPERATURE_PRECISION 9
+
+#define ONE_WIRE_BUS 4                 // Data wire is plugged into port 2 on the Arduino
+#define TEMPERATURE_PRECISION 9        // 9 bits or one decimal point

 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
-OneWire oneWire(ONE_WIRE_BUS);
-// Pass our oneWire reference to Dallas Temperature.
-DallasTemperature sensors(&oneWire);
-DeviceAddress casingTemperature, ambientTemperature;
-// OneWire variables
+OneWire oneWire(ONE_WIRE_BUS);
+
+DallasTemperature sensors(&oneWire);                  // Pass our oneWire reference to Dallas Temperature.
+DeviceAddress casingTemperature, ambientTemperature, glandTemperature;   // OneWire variables
 unsigned long lastTempRequest = 0;
 int  delayInMillis = 0;
 float ambient_temperature = 0.0;
 float casing_temperature = 0.0;
+float gland_temperature = 0.0;
 int  idle = 0;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//                                           2. SHAFT TEMPERATURE SENSOR
+//
+// This device uses a 2KHz SPI protocol and has no memory scratchpad to read from so data must be read sequentially
+// according to its clock speed It takes approximately 470ms for a reading and the data is five bytes long.
+
+#define  ClockPin  6  // clock in
+#define  DataPin   7  //data in
+#define  TestPin   8  //driver pin  set pin low to start deliver data
+
+float shaftTemp = 0.0;
+
+void data_read(int *p)
+{
+  int i,j,PinState,tempData;
+  digitalWrite(TestPin, LOW);              //start device transmission
+  for(i=0;i<5;i++) {                       //read 5 bytes
+    for(j=0;j<8;j++){                      //read 8 bits
+      do{
+        PinState = digitalRead(ClockPin);
+      } while(PinState);                   //sync to clock by waiting for change to LOW
+      delayMicroseconds(100);              //buffer
+      PinState = digitalRead(DataPin);     //read data bit
+      if(1 == PinState)
+        tempData = (tempData<<1 & 0xfe)+1; //add 1
+      else
+        tempData = (tempData<<1 & 0xfe);   //add 0
+      do{
+        PinState = digitalRead(ClockPin);  //get stuck until clock changes
+      }while(PinState != 1);
+    }
+  *p++ = tempData;                         //pass byte to array pointer address
+  }
+  digitalWrite(TestPin, HIGH);             //stop device transmission
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                                  2. TACHOMETER
+//                                                  3. TACHOMETER
 const byte TACH = 2;
 const byte DURATION = 1;
-volatile boolean revolution_occured = false;
+volatile boolean revolution_occured = false;
 unsigned int revolution_count = 0;
 unsigned int current_time = 0;
 unsigned int previous_time = 0;
 unsigned int rpm = 0;

 // Tachometer Interrupt Service Routine (ISR)
-void revolution ()
-{
+
+void revolution (){
   revolution_occured = true;
-}
-
+  }

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                                 3. LOAD WASHER 1 & 2
+//                                                 4. LOAD WASHER 1 & 2

 int loadWasher1Pin = A0;
 int loadWasher2Pin = A1;
@@ -81,7 +117,7 @@
 double load2_in_lbs = 0;

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                                4. LEVEL SENSOR
+//                                                5. LEVEL SENSOR

 int levelSensorPin = A2;

@@ -103,7 +139,7 @@

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                                5. SOLENOID DRAIN VALVE
+//                                                6. SOLENOID DRAIN VALVE

 int solenoidValvePin = 5; //Pin controlling the valve
@@ -117,24 +153,19 @@

 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                           6. SERIAL MONITOR
+//                                                7. SERIAL MONITOR
 unsigned int long PRINT_DELAY = 2000; //in milliseconds
 unsigned int long last_print_time = 0;
 String data;

-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//                                           7. SHAFT TEMPERATURE SENSOR
-#define  ClockPin  6  // clock in
-#define  DataPin   7  //data in
-#define  TestPin   8 //driver pin  set pin low to start deliver data
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////

 void setup()
 {
-  Serial.begin(9600);   //Enable serial at high speed
-  analogReference(EXTERNAL);
+  Serial.begin(9600);        //Enable serial at high speed
+  analogReference(EXTERNAL); //Important or we send 5V into the 3V3 pin!

   // Tachometer setup
   pinMode(solenoidValvePin,OUTPUT);
@@ -145,26 +176,29 @@
   sensors.begin();
   if (!sensors.getAddress(ambientTemperature, 0)) Serial.println("Unable to find address for Device 0");
   if (!sensors.getAddress(casingTemperature, 1)) Serial.println("Unable to find address for Device 1");
+  if (!sensors.getAddress(glandTemperature, 2)) Serial.println ("Unable to find address for Device 2");
   sensors.setResolution(ambientTemperature, TEMPERATURE_PRECISION);
   sensors.setResolution(casingTemperature, TEMPERATURE_PRECISION);
-  sensors.setWaitForConversion(false);
+  sensors.setResolution(glandTemperature, TEMPERATURE_PRECISION);
+  sensors.setWaitForConversion(false);      //Important undocumented feature that is only needed for "parasitic mode"
   sensors.requestTemperatures();
   delayInMillis = 750 / (1 << (3));
   lastTempRequest = millis();

-//Initialize load washer samples
-for (int i = 0; i<load_sample_window; i++){
-  load1_samples[i]=0;
-  load2_samples[i]=0;
-
-
+  //Initialize load washer samples
+  for (int i = 0; i<load_sample_window; i++){
+    load1_samples[i]=0;
+    load2_samples[i]=0;
+  }
+
+
+  //Initialize SEN0093 pins (shaft temperature)
   pinMode(DataPin,INPUT);
   pinMode(ClockPin,INPUT);
   pinMode(TestPin,OUTPUT);
   digitalWrite(TestPin, HIGH);
   delay(100);
-}

 }

@@ -174,12 +208,12 @@
    ////////////////////////////////////////////////////////Tachometer
    // Check if tach was triggered
    if (revolution_occured) {
-   revolution_count ++;
-   revolution_occured = !revolution_occured;
+     revolution_count ++;
+     revolution_occured = !revolution_occured;
    }

- // Calculate RPM
- current_time = millis();
+   // Calculate RPM
+   current_time = millis();
    if (current_time - previous_time >= 1000) {
      rpm = (revolution_count / DURATION * 60);
      previous_time = current_time;
@@ -188,108 +222,103 @@

   /////////////////////////////////////////////////////////Temperature

-  if (millis() - lastTempRequest >= delayInMillis) // waited long enough??
-  {
+  if (millis() - lastTempRequest >= delayInMillis) {    // waited long enough??
     ambient_temperature = sensors.getTempCByIndex(0);
     casing_temperature = sensors.getTempCByIndex(1);
+	gland_temperature = sensors.getTempCByIndex (2);
     sensors.requestTemperatures();
     delayInMillis = 750 / (1 << (3));
     lastTempRequest = millis();
   }

-//////////////////////////////////////////////////////Load Washer
-
- load1_samples[index_i] = analogRead(loadWasher1Pin);
- load2_samples[index_i] = analogRead(loadWasher2Pin);
- index_i = (index_i + 1)%load_sample_window;
-
- load1_value = 0;
- for (int j = 0; j < load_sample_window; j++){
-  load1_value+= load1_samples[j];
- }
- load1_value = load1_value / load_sample_window;
-
-
- load2_value = 0;
- for (int j = 0; j < load_sample_window; j++){
-  load2_value+= load2_samples[j];
- }
- load2_value = load2_value / load_sample_window;
-
-
-
-
-
- load1_in_lbs = ( load1_value - B_reference_level ) / A_linear_rate;
- load2_in_lbs = ( load2_value - B_reference_level ) / A_linear_rate;
-
- //TODO: Send this value to the cloud for storage and analytics
-
-
- //////////////////////////////////////////////////////Water Level Sensor
-
- analog_water_level = analogRead(levelSensorPin);
- water_level_cm = ( analog_water_level - B_water_reference_level ) / A_water_rate;
-
-//Set the reference water level for a calculation (when appropriate)
-
-if(initialize==true){
-  flow_calc_water_level_cm = water_level_cm;
-  calc_time_ms = millis();
-  initialize=false;
-}
-
-
-
- //////////////////////////////////////////////////////Solenoid Drain Valve
-
- //Start the drain if the water level is too high
- if(water_level_cm >= drain_at_cm_level){
-  //TODO: If water level is way too high, then water is accumulating so send the operator a warning message
-  digitalWrite(solenoidValvePin,HIGH);
-  solenoid_valve_open = true;
- }
-
-
-
- if (solenoid_valve_open == false){
-
-  if (water_level_cm >= (flow_calc_water_level_cm + water_level_buffer)){
-
-
-   float water_level_delta = analog_water_level - flow_calc_water_level_cm;
-   unsigned long time_delta = millis() - calc_time_ms;
-   flow_rate_cc_per_min = ( water_level_delta ) / (time_delta);
-//   flow_calc_water_level_cm = analog_water_level;
-  }
- }
-
-  if (water_level_cm <= close_valve_at_cm_level){
-  digitalWrite(solenoidValvePin,LOW);
-  solenoid_valve_open = false;
-  initialize=true;
- }
-
-
-  //////////////////////////////////////////////////////Shaft Temperature
-  int data_buf[5] = {0};
-  int tempData = 0;
-
-  data_read(data_buf);
-  tempData = data_buf[1]*256 + data_buf[2];
-  float realTemp = (float)tempData/16-273.15;
-
-  //////////////////////////////////////////////////////Printing
+  //////////////////////////////////////////////////////Load Washer
+
+  load1_samples[index_i] = analogRead(loadWasher1Pin);
+  load2_samples[index_i] = analogRead(loadWasher2Pin);
+  index_i = (index_i + 1)%load_sample_window;
+
+
+  //////////////////////////////////////////////////////Water Level Sensor
+
+  analog_water_level = analogRead(levelSensorPin);
+  water_level_cm = ( analog_water_level - B_water_reference_level ) / A_water_rate;
+
+
+
+  //////////////////////////////////////////////////////Printing
+  // Every PRINT_DELAY, disable ISR and do calculations which otherwise block the flow of the main loop,
+  // including printing to serial that sends data to relay node.
+

   if (millis() - last_print_time >= PRINT_DELAY){
-    data = "";
-//    data += ambient_temperature;
-//    data += ",";
-//    data += realTemp;
-//    data += ",";
-//    data += casing_temperature;
-//    data += ",";
+    detachInterrupt (0);  // disable tachometer interrupt
+
+	//////////////////////////////////////////////////////Calculate load washer averages - ??? ms
+	load1_value = 0;
+    for (int j = 0; j < load_sample_window; j++){
+      load1_value+= load1_samples[j];
+    }
+    load1_value = load1_value / load_sample_window;
+
+    load2_value = 0;
+    for (int j = 0; j < load_sample_window; j++){
+      load2_value+= load2_samples[j];
+      }
+    load2_value = load2_value / load_sample_window;
+
+    load1_in_lbs = ( load1_value - B_reference_level ) / A_linear_rate;
+    load2_in_lbs = ( load2_value - B_reference_level ) / A_linear_rate;
+
+    //////////////////////////////////////////////////////Shaft Temperature - 460 ms
+    int data_buf[5] = {0};
+    int tempData = 0;
+    data_read(data_buf);
+    tempData = data_buf[1]*256 + data_buf[2];
+    shaftTemp = (float)tempData/16-273.15;
+
+	//////////////////////////////////////////////////////Solenoid Drain Valve - ??? ms
+    //Start the drain if the water level is too high
+    if(water_level_cm >= drain_at_cm_level){
+      //TODO: If water level is way too high, then water is accumulating so send the operator a warning message
+      digitalWrite(solenoidValvePin,HIGH);
+      solenoid_valve_open = true;
+    }
+
+   if (solenoid_valve_open == false){
+     if (water_level_cm >= (flow_calc_water_level_cm + water_level_buffer)){
+       float water_level_delta = analog_water_level - flow_calc_water_level_cm;
+       unsigned long time_delta = millis() - calc_time_ms;
+       flow_rate_cc_per_min = ( water_level_delta ) / (time_delta);
+       //   flow_calc_water_level_cm = analog_water_level;
+     }
+   }
+
+   if (water_level_cm <= close_valve_at_cm_level){
+     digitalWrite(solenoidValvePin,LOW);
+     solenoid_valve_open = false;
+     initialize=true;
+   }
+
+	///////////////////////////////////////////////////////Water lever sensor calculations - ??? ms
+	//Set the reference water level for a calculation (when appropriate)
+    if(initialize==true){
+      flow_calc_water_level_cm = water_level_cm;
+      calc_time_ms = millis();
+      initialize=false;
+    }
+
+
+	//////////////////////////////////////////////////////Printing
+	data = "";
+    data += shaftTemp;
+    data += ",";
+	data += ambient_temperature;
+    data += ",";
+    data += casing_temperature;
+    data += ",";
+	data += gland_temperature;
+	data += "'";
     data += rpm;
     data += ",";
     data += load1_in_lbs;
@@ -303,36 +332,13 @@
     data += flow_rate_cc_per_min;

     Serial.println (data);
-
+
+	attachInterrupt (0, revolution, RISING);  // re-attach interrupt handler for tachometer
     last_print_time = millis();
   }
 }

-void data_read(int *p)
-{
-  int i,j,PinState,tempData;
-
-  digitalWrite(TestPin, LOW);
-  for(i=0;i<5;i++)
-  {
-  for(j=0;j<8;j++)
-  {
-    do{
-      PinState = digitalRead(ClockPin);
-    }while(PinState);
-    delayMicroseconds(100);
-    PinState = digitalRead(DataPin);
-    if(1 == PinState)
-      tempData = (tempData<<1 & 0xfe)+1;
-    else
-      tempData = (tempData<<1 & 0xfe);
-    do{
-      PinState = digitalRead(ClockPin);
-    }while(PinState != 1);
-  }
-  *p++ = tempData;
-  }
-  digitalWrite(TestPin, HIGH);
-}
-
-
+
+
+
+


Ajustando leituras para salvar RGB

Ajustando leituras para salvar RGB

--- ESP-Logger/ESP-Logger.ino
+++ ESP-Logger/ESP-Logger.ino
@@ -8,12 +8,17 @@
 #define FANPIN D6
 #define LIGHTPIN D5
 #define SENSORPIN D8
+
+#define REDPIN D7
+#define GREENPIN D0
+#define BLUEPIN D3
+
 #define DHTTYPE DHT11
-#define DELAY_TIME_TO_SEND  360 // 5 min
+#define DELAY_TIME_TO_SEND  360
 #define TABLE_LEITURA "leitura"
 #define TABLE_MOTION "motion"
-#define CLIENT_EMAIL "well.oliveira.snt@gmail.com"
-#define DEVICE_PATH "/devices/mkW3jbNvyKMzC8FLODaQd7GAum02/"
+#define CLIENT_EMAIL "well.oliveira.snt@gmail.com"
+#define DEVICE_PATH "/devices/mkW3jbNvyKMzC8FLODaQd7GAum023/"

 DHT dht(DHTPIN, DHTTYPE);

@@ -21,7 +26,13 @@
 JsonObject &leitura = jsonBuffer.createObject();
 JsonObject &motion = jsonBuffer.createObject();

-int count = 15000;
+int r = 0;
+int g = 0;
+int b = 0;
+
+int errorCount = 0;
+
+int count = DELAY_TIME_TO_SEND;
 bool motionSensorRead = false;

 void setup() {
@@ -43,10 +54,16 @@
     pinMode(FANPIN, OUTPUT);
     pinMode(LIGHTPIN, OUTPUT);
     pinMode(SENSORPIN, INPUT);
+    pinMode(REDPIN, OUTPUT);
+    pinMode(GREENPIN, OUTPUT);
+    pinMode(BLUEPIN, OUTPUT);
+
     motionSensorRead = !digitalRead(SENSORPIN);
     digitalWrite(LED_BUILTIN, !Firebase.getBool(String(DEVICE_PATH) + "light"));

 }
+
+void(* resetFunc) (void) = 0;

 inline String getErrorString(String table) {
     return String(TABLE_LEITURA) + " failed to send:";
@@ -91,20 +108,21 @@

 void inline readLeituraAndSendToFirebase() {
     readDataToSend();
-
     if (count > DELAY_TIME_TO_SEND) {
-
         if (leitura["temperatura"] == "nan" || leitura["umidade"] == "nan" || getEpoch().toInt() <= 1000) {
+            Serial.print("Leitura falha");
             return;
         }

         count = 0;
         Firebase.push(TABLE_LEITURA, leitura);
+        Serial.print("Enviou leitura");
+        return;
     }
-
     if (Firebase.failed()) {
         Serial.print(getErrorString(TABLE_LEITURA));
         Serial.println(Firebase.error());
+        errorCount++;
         return;
     }
 }
@@ -113,6 +131,21 @@
     digitalWrite(FANPIN, !Firebase.getBool(String(DEVICE_PATH) + "fan"));
     digitalWrite(LIGHTPIN, !Firebase.getBool(String(DEVICE_PATH) + "light"));
     digitalWrite(LED_BUILTIN, !Firebase.getBool(String(DEVICE_PATH) + "light"));
+
+    int rAux = Firebase.getInt(String(DEVICE_PATH) + "r");
+    int bAux = Firebase.getInt(String(DEVICE_PATH) + "b");
+    int gAux = Firebase.getInt(String(DEVICE_PATH) + "g");
+
+    r = rAux != 0 ? rAux : r ;
+    b = bAux != 0 ? bAux : b ;
+    g = gAux != 0 ? gAux : g ;
+
+    Serial.println( "r: " + String(r) + ", " +
+                    "b: " + String(b) + ", " +
+                    "g: " + String(g) );
+    analogWrite(REDPIN, r);
+    analogWrite(GREENPIN, g);
+    analogWrite(BLUEPIN, b);
 }

 //TODO verify wheter is this okay or not
@@ -130,6 +163,16 @@
     Serial.println("------Count------/");
 }

+void inline updateCountErrosAndPrint() {
+    if(errorCount > 1000) {
+        Serial.println("/-----errorCount-------");
+        Serial.println(errorCount);
+        Serial.println("------errorCount------/");
+        errorCount = 0;
+        resetFunc();
+    }
+}
+
 void loop() {
     updateNtp();
     readMotionSensorAndSendToFirebase();


Using pin 0 and inverted logic

Using pin 0 and inverted logic

--- ESP32/ble_button/ble_button.ino
+++ ESP32/ble_button/ble_button.ino
@@ -6,7 +6,7 @@
 #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
 #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

-#define INPUT_PIN 33
+#define INPUT_PIN 0
 #define DEBOUNCE_TIME_MILLIS 50

 BLEServer* pServer = NULL;
@@ -64,7 +64,7 @@
   if(connected == true){
     // Read input and store
     uint8_t value =  0;
-    if(digitalRead(INPUT_PIN) == HIGH){
+    if(digitalRead(INPUT_PIN) == LOW){
       value = 1;
     }


v4.4 Improve random number logic

v4.4 Improve random number logic

--- WeatherDisplay.ino
+++ WeatherDisplay.ino
@@ -286,20 +286,16 @@

   // Get random number
   byte maxRandomNumber = sizeof(textColor) / sizeof(unsigned int);
-  randomColor =  random(maxRandomNumber);
+  randomColor = random(maxRandomNumber);
   // If random number repeats, try again
   while (randomColor == lastRandomNumber) {
     randomColor = random(maxRandomNumber);
   }
   lastRandomNumber = randomColor;
-  if (randomColor == 0) {
-    anotherRandomColor = randomColor + 1;
-  }
-  else if (randomColor == 6) {
-    anotherRandomColor = randomColor - 1;
-  }
-  else {
-    anotherRandomColor = randomColor + 1;
+  anotherRandomColor = random(maxRandomNumber);
+  // If random number repeats, try again
+  while (anotherRandomColor == randomColor) {
+    randomColor = random(maxRandomNumber);
   }
   tft.setTextColor(textColor[randomColor]);
   tft.setTextSize(1);


Free things after we're done with them

Free things after we're done with them

--- alarm.ino
+++ alarm.ino
@@ -105,11 +105,13 @@
     linked_list_t * iterator = action_times;
     while (iterator != NULL) {
         if (GET_MEMBER(action_times, action_time_t, alarmno) == alarmno) {
+            linked_list_t * to_delete = iterator;
             if (prev_iter == NULL)
-                action_times = iterator->next;
+                iterator = action_times = iterator->next;
             else
-                prev_iter->next = iterator->next;
-            free(iterator);
+                iterator = prev_iter->next = iterator->next;
+            free(to_delete->item);
+            free(to_delete);
         }
         prev_iter = iterator;
         NEXT(iterator);


Create NRF24L01-Mask.ino

Create NRF24L01-Mask.ino

--- NRF24L01/Mask/NRF24L01-Mask.ino
+++ NRF24L01/Mask/NRF24L01-Mask.ino
@@ -2,7 +2,7 @@
  *
  *  by Brandon C. Allen
  *
- *   *  Hardware Used:
+ *  Hardware Used:
  *  Adafruit Feather M0 Proto
  *  https://www.adafruit.com/product/2772
  *  Eight Adafruit DotStar High Density 8x8 Grid - 64 RGB LED Pixel Matrices


updates for new board layout, wip debugging stuff

--- LedDisplay/LedDisplay.ino
+++ LedDisplay/LedDisplay.ino
@@ -1,25 +1,29 @@
 #include <arduino.h>

+// led on device
+const int ledPin = 13;
+const int hackPin = 8;
+
 // shared pins
-int outputDisabledPin = 9;
-int registerClockPin = 10;
+const int outputDisabledPin = 3;
+const int registerClockPin = 11;

 // segment pins
-int whichSegmentData = 2;
-int segmentShiftRegisterClockPin = 4;
+const int whichSegmentData = 9;
+const int segmentShiftRegisterClockPin = 10;

 // digit pins
-int whichDigitData = 11;
-int shiftRegisterClockPin = 12;
+const int whichDigitData = 6;
+const int digitShiftRegisterClockPin = 5;

-const int segTop = (1 << 0);
+const int segTop = (1 << 7);
 const int segDot = (1 << 1);
-const int segMiddle = (1 << 2);
-const int segBottomRight = (1 << 3);
-const int segBottomLeft = (1 << 4);
-const int segBottom = (1 << 5);
+const int segMiddle = (1 << 5);
+const int segBottomRight = (1 << 4);
+const int segBottomLeft = (1 << 2);
+const int segBottom = (1 << 3);
 const int segTopLeft = (1 << 6);
-const int segTopRight = (1 << 7);
+const int segTopRight = (1 << 0);

 byte segmentIndex = 0;
 int valueToDisplay = 0;
@@ -42,25 +46,60 @@

 void setup()
 {
-  Serial.begin(9600);
-  Serial.println();
-
+  //Serial.begin(9600);
+  //Serial.println();
+
+  pinMode(ledPin, OUTPUT);
+  pinMode(hackPin, OUTPUT);
   pinMode(outputDisabledPin, OUTPUT);
   pinMode(registerClockPin, OUTPUT);
   pinMode(whichSegmentData, OUTPUT);
   pinMode(segmentShiftRegisterClockPin, OUTPUT);
   pinMode(whichDigitData, OUTPUT);
-  pinMode(shiftRegisterClockPin, OUTPUT);
+  pinMode(digitShiftRegisterClockPin, OUTPUT);

   digitalWrite(outputDisabledPin, LOW);
+  digitalWrite(registerClockPin, LOW);
+  digitalWrite(whichSegmentData, LOW);
+  digitalWrite(segmentShiftRegisterClockPin, LOW);
+  digitalWrite(whichDigitData, LOW);
+  digitalWrite(digitShiftRegisterClockPin, LOW);
+
+  //shiftOut(whichSegmentData, segmentShiftRegisterClockPin, MSBFIRST, 255);
+  //shiftOut(whichDigitData, digitShiftRegisterClockPin, MSBFIRST, 0);
+  //digitalWrite(registerClockPin, HIGH);
+  //digitalWrite(registerClockPin, LOW);

-  writeValue(0, 0);
-  valueToDisplay = 0;
+  valueToDisplay = 1234;
+  writeValue(0, valueToDisplay);
+}
+
+bool toggle = false;
+unsigned long lastToggle = 0;
+
+void loop2()
+{
+  unsigned long now = millis();
+
+  if (now - lastToggle > 3000)
+  {
+    toggle = !toggle;
+    lastToggle = now;
+  }
+
+  unsigned long pinValue = toggle ? HIGH : LOW;
+  digitalWrite(ledPin, pinValue);
+  digitalWrite(hackPin, pinValue);
+  //digitalWrite(registerClockPin, pinValue);
+  //digitalWrite(whichSegmentData, pinValue);
+  //digitalWrite(segmentShiftRegisterClockPin, pinValue);
+  //digitalWrite(whichDigitData, pinValue);
+  //digitalWrite(digitShiftRegisterClockPin, pinValue);
 }

 void loop()
 {
-  // Arduino pow function is approximage and sometimes will end up rounding down when casting to int
+  // Arduino pow function is approximate and sometimes will end up rounding down when casting to int
   int place = pow(10, 3 - segmentIndex) + 0.5f;
   int segmentValue = (valueToDisplay / place) % 10;

@@ -71,9 +110,11 @@
   unsigned long now = millis();
   if (now > lastIncrement + 20)
   {
-    valueToDisplay++;
+    valueToDisplay = (valueToDisplay + 1) % 10000;
     lastIncrement = now;
   }
+
+  digitalWrite(ledPin, (now % 200 == 0) ? HIGH : LOW);
 }

 void writeValue(byte digit, byte value)
@@ -82,7 +123,7 @@
   int segmentData = digitValues[value];

   shiftOut(whichSegmentData, segmentShiftRegisterClockPin, MSBFIRST, segmentData);
-  shiftOut(whichDigitData, shiftRegisterClockPin, MSBFIRST, digitData);
+  shiftOut(whichDigitData, digitShiftRegisterClockPin, MSBFIRST, digitData);

   digitalWrite(registerClockPin, HIGH);
   digitalWrite(registerClockPin, LOW);


Int. receive test

Int. receive test

Testing the code from this page
http://forum.arduino.cc/index.php/topic,16717.0.html to send just
integers rather than a string.

--- RadioReceiver/RadioReceiver.ino
+++ RadioReceiver/RadioReceiver.ino
@@ -10,38 +10,54 @@

 #include <VirtualWire.h>
 int receive_pin = 2;
-
+int numbers[3]; // Change 3 to number of integers you wish to send.

 void setup()
 {
   Serial.begin(9600);	// Debugging only
-  Serial.println("setup");
+  Serial.println("Setting up receiver");

   // Initialise the IO and ISR
   vw_set_rx_pin(receive_pin);
   vw_set_ptt_inverted(true); // Required for DR3100
   vw_setup(1200);	 // Bits per sec
-
   vw_rx_start();       // Start the receiver PLL running
+  Serial.println("Receiver ready!");
+
 }
-
-

 void loop()
 {
-
   uint8_t buf[VW_MAX_MESSAGE_LEN];
   uint8_t buflen = VW_MAX_MESSAGE_LEN;
-  if (vw_get_message(buf, &buflen))
+
+  if (vw_get_message(buf, &buflen)) // check to see if anything has been received
   {
-    int i;
-    for (int i=0;i<buflen;i++)
+    Serial.print(buflen, DEC);
+    Serial.println(" bytes received!");
+
+    for (int i = 0; i < buflen; i++)
     {
-      Serial.write(buf[i]);
-      Serial.print("");
+      Serial.print("buf[");
+      Serial.print(i, DEC);
+      Serial.print("]=");
+      Serial.print(buf[i], DEC);
+      Serial.print("  ");
     }
-
-    Serial.println("");
+    Serial.println();
+
+    //memcpy(buf, numbers, buflen);
+    for (int i = 0; i < 3; i++)
+    {
+      numbers[i] = word(buf[i*2+1], buf[i*2]);
+      Serial.print("numbers[");
+      Serial.print(i, DEC);
+      Serial.print("]=");
+      Serial.print(numbers[i], DEC);
+      Serial.print("  ");
+    }
+    Serial.println();
   }
-}
-
+
+  delay(50);
+}


Update enroll.ino

Update enroll.ino

--- firmware/examples/enroll/enroll.ino
+++ firmware/examples/enroll/enroll.ino
@@ -16,7 +16,7 @@
   !!! Adapted for Spark Core by Paul Kourany, May 2014 !!!
  ****************************************************/

-#include "Adafruit_Fingerprint.h"
+#include "Adafruit_Fingerprint/Adafruit_Fingerprint.h"

 #if defined (SPARK)
 //


Time adjustment pushbuttons working

Time adjustment pushbuttons working

Last hardware to re-add is the led.

--- fourtwentyclock/fourtwentyclock.ino
+++ fourtwentyclock/fourtwentyclock.ino
@@ -117,7 +117,9 @@
   int decimalTime = now.hour() * 100 + now.minute();

   int hourPlusState = digitalRead(hourPlusButton);
+  int hourMinusState = digitalRead(hourMinusButton);
   int minPlusState = digitalRead(minPlusButton);
+  int minMinusState = digitalRead(minMinusButton);

   if (hourPlusState == HIGH)                                   // Hour+ Button
   {
@@ -127,6 +129,14 @@
     delay(bounceDelay);
   }

+  if (hourMinusState == HIGH)                                   // Hour- Button
+  {
+    adjustedHour = hourCount * 100;
+    decimalTime += adjustedHour;
+    hourCount--;
+    delay(bounceDelay);
+  }
+
   if (minPlusState == HIGH)                                      // Minute+ Button
   {
     adjustedMinute = minuteCount + 1;
@@ -134,18 +144,26 @@
     delay(bounceDelay);
   }

+  if (minMinusState == HIGH)                                     // Minute- Button
+  {
+    adjustedMinute = minuteCount - 1;
+    minuteCount--;
+    delay(bounceDelay);
+  }
+
   decimalTime += adjustedHour + adjustedMinute;
+
   if (now.hour() + hourCount * 100 > 1100) hourCount = 0;
   if (now.minute() + minuteCount > 58) minuteCount = 0;
+
   if (decimalTime > 1259) decimalTime -= 1200;
   if (decimalTime < 59) decimalTime += 1200;

-
   return decimalTime;
 }

-void displayDay ()                                // Grab Day Number & Display Letters
+void displayDay ()                                                // Convert Day Number to Display Letters
 {
   DateTime now = RTC.now();
   int daynumber = now.dayOfWeek();
@@ -198,13 +216,13 @@
   int clockBrightness = map(brightReading, 0, 1023, 1, 15);
   neoBrightness =  map(brightReading, 0, 1023, 100, 255);

-  int brightSwitchRead = digitalRead(brightSwitch);
+  int brightSwitchRead = digitalRead(brightSwitch);
   if (brightSwitchRead == HIGH)
   {
     disp.setBrightness(clockBrightness);
     alpha4.setBrightness(clockBrightness);
   }
-  else strip.setBrightness(neoBrightness);
+  else strip.setBrightness(neoBrightness);
 }


Added library information

Added library information

--- src/cyclop_plus/cyclop_plus.ino
+++ src/cyclop_plus/cyclop_plus.ino
@@ -6,6 +6,9 @@
   point for the code base, even if little of the actual code remains.
   Without those projects CYCLOP+ would not have been created. All possible
   credit goes to the two mentioned projects and their contributors.
+
+  I have used wonho-makers Adafruit_SH1106 library to add support for OLED
+  screens with an SH1106 controller. The default is to use SSD1306 OLEDs.

   The MIT License (MIT)


Implemented a SNR and get response standard function

--- RFIDreader/RFIDreader.ino
+++ RFIDreader/RFIDreader.ino
@@ -25,7 +25,7 @@
 // command packet - start, address, data length, command, data[0 to 2], end
 // response packet when idle - 0xAA, 0x00, 0x02, 0x01, 0x83, 0x80, 0xBB
 char get_readID[] = { 0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB };
-byte response[15];
+byte response[16];

 const int ledPin = 13;
 const int signalPin = 4;


Allow call from interrupt or event handler.

--- examples/Analyzer/CosaAnalyzerJob/CosaAnalyzerJob.ino
+++ examples/Analyzer/CosaAnalyzerJob/CosaAnalyzerJob.ino
@@ -37,6 +37,13 @@
 #include "Cosa/Trace.hh"
 #include "Cosa/IOStream/Driver/UART.hh"

+// Select call from interrupt service routine or event handler. Latency:
+// Interrupt Service Routine: 1-5 us
+// Event Handler: 20-25 us
+
+#define SERVICE on_expired
+// #define SERVICE run
+
 class Work : public Job, private OutputPin {
 public:
   Work(Job::Scheduler* scheduler,
@@ -50,7 +57,7 @@
     expire_at(delay);
   }

-  virtual void run()
+  virtual void SERVICE()
   {
     toggle();
     m_chain->expire_after(m_delay);