Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update to allow always send.

  • Loading branch information...
commit 67cb51d4680b1ca916c4ef62ed9d84a70008f814 1 parent 090f08d
@voodootikigod authored
Showing with 36 additions and 1 deletion.
  1. +36 −1 firmware/firmware.cpp
View
37 firmware/firmware.cpp
@@ -1,7 +1,9 @@
int DEBUG=1;
+TCPClient client;
+
+bool reading[20];
-TCPClient client;
long SerialSpeed[] = {600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200};
void ipArrayFromString(byte ipArray[], String ipString) {
@@ -41,10 +43,38 @@ void setup() {
Spark.function("connect", connectToMyServer);
if(DEBUG)
Serial.begin(115200);
+}
+
+void report() {
+ int action = 0x03;
+ for (int i = 0; i < 20; i++) {
+ if (reading[i]) {
+ if (i < 10 && (reading[i] & 1)) {
+ // Digital pins are 0-9 and can only do digital read
+ client.write(0x03);
+ client.write(i);
+ client.write(digitalRead(i));
+ } else {
+ if (reading[i] & 1) {
+ client.write(0x03);
+ client.write(i);
+ client.write(digitalRead(i));
+ } else if (reading[i] & 2) {
+ client.write(0x04);
+ client.write(i);
+ client.write(analogRead(i));
+ }
+ }
+ }
+ }
}
+
void loop() {
+
+ report();
+
if (client.connected()) {
if (client.available()) {
// parse and execute commands
@@ -93,6 +123,11 @@ void loop() {
client.write(pin);
client.write(val);
break;
+ case 0x05: // set always send bit
+ pin = client.read();
+ val = client.read();
+ reading[pin] = val;
+ break;
// Serial API
Please sign in to comment.
Something went wrong with that request. Please try again.