From 5f6c5633e6abe57d1479fa1756e6e44f6ac21267 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 23 May 2019 00:43:06 +0100
Subject: [PATCH] Create entropy test sketch for random ids

---
 .gitmodules                     |  3 +++
 README.md                       |  4 ++++
 iot/EntropyTest/Entropy.cpp     |  1 +
 iot/EntropyTest/Entropy.h       |  1 +
 iot/EntropyTest/EntropyTest.ino | 39 +++++++++++++++++++++++++++++++++
 iot/libraries/Entropy           |  1 +
 6 files changed, 49 insertions(+)
 create mode 120000 iot/EntropyTest/Entropy.cpp
 create mode 120000 iot/EntropyTest/Entropy.h
 create mode 100644 iot/EntropyTest/EntropyTest.ino
 create mode 160000 iot/libraries/Entropy

diff --git a/.gitmodules b/.gitmodules
index ecc03d9..9c1c84f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule "lantern-build-engine"]
 	path = lantern-build-engine
 	url = https://gitlab.com/sbrl/lantern-build-engine.git
+[submodule "iot/libraries/Entropy"]
+	path = iot/libraries/Entropy
+	url = https://github.com/taoyuan/Entropy.git
diff --git a/README.md b/README.md
index f6e9652..52b0f53 100644
--- a/README.md
+++ b/README.md
@@ -14,3 +14,7 @@
  - [Battery](https://smile.amazon.co.uk/Anker-PowerCore-Aluminum-Portable-Lipstick-Sized-Black/dp/B005QI1A8C/) - Size currently unknown - I'll need to run some tests to see how much power it uses to figure out the right battery size.
  - [Project box](https://smile.amazon.co.uk/waterproof-plastic-Enclosure-Power-junction-Grey/dp/B01JHBHNMA/) - if we can't 3D print one
  - [TPL-5111](https://www.adafruit.com/product/3573) - also available from Pimoroni
+
+
+## Useful Links
+ - Entropy extraction from the watchdog timer vs the internal clock: https://github.com/taoyuan/Entropy
diff --git a/iot/EntropyTest/Entropy.cpp b/iot/EntropyTest/Entropy.cpp
new file mode 120000
index 0000000..ad2c5f0
--- /dev/null
+++ b/iot/EntropyTest/Entropy.cpp
@@ -0,0 +1 @@
+../libraries/Entropy/Entropy.cpp
\ No newline at end of file
diff --git a/iot/EntropyTest/Entropy.h b/iot/EntropyTest/Entropy.h
new file mode 120000
index 0000000..0fe1f53
--- /dev/null
+++ b/iot/EntropyTest/Entropy.h
@@ -0,0 +1 @@
+../libraries/Entropy/Entropy.h
\ No newline at end of file
diff --git a/iot/EntropyTest/EntropyTest.ino b/iot/EntropyTest/EntropyTest.ino
new file mode 100644
index 0000000..4c4f219
--- /dev/null
+++ b/iot/EntropyTest/EntropyTest.ino
@@ -0,0 +1,39 @@
+// Generate_Random_Numbers - This sketch makes use of the Entropy library
+// to produce a sequence of random integers and floating point values.
+// to demonstrate the use of the entropy library
+//
+// Copyright 2012 by Walter Anderson
+//
+// This file is part of Entropy, an Arduino library.
+// Entropy is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Entropy 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Entropy.  If not, see <http://www.gnu.org/licenses/>.
+// 
+// Edited by Starbeamrainbowlabs 2019
+
+#include "Entropy.h"
+
+void setup() {
+	Serial.begin(9600);
+
+	// This routine sets up the watch dog timer with interrupt handler to maintain a
+	// pool of real entropy for use in sketches. This mechanism is relatively slow
+	// since it will only produce a little less than two 32-bit random values per
+	// second.
+	Entropy.initialize();
+}
+
+void loop() {
+	uint32_t random_long;
+	random_long = Entropy.random();
+	Serial.println(random_long);
+}
diff --git a/iot/libraries/Entropy b/iot/libraries/Entropy
new file mode 160000
index 0000000..807c45c
--- /dev/null
+++ b/iot/libraries/Entropy
@@ -0,0 +1 @@
+Subproject commit 807c45cfe3e48422559b2aed5bc7de28df15ab3d
