From 04e4be51a2474bb37c9eaa962aca4568ab8f8c27 Mon Sep 17 00:00:00 2001 From: Shabir Mohamed Date: Wed, 22 Jul 2015 17:59:35 +0530 Subject: [PATCH] added mqtt support for sending device controls --- .../src/sketches/firealarm_wifi/Connect.ino | 16 ++++++---------- .../sketches/firealarm_wifi/FireAlarmWifiAgent.h | 2 +- .../firealarm_wifi/FireAlarmWifiAgent.ino | 4 ++-- .../src/sketches/firealarm_wifi/Listener.ino | 3 ++- .../src/sketches/sensebot_wifi/HttpServer.ino | 1 + 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/distribution/src/sketches/firealarm_wifi/Connect.ino b/modules/distribution/src/sketches/firealarm_wifi/Connect.ino index 3e62652a..f6528ce8 100644 --- a/modules/distribution/src/sketches/firealarm_wifi/Connect.ino +++ b/modules/distribution/src/sketches/firealarm_wifi/Connect.ino @@ -65,7 +65,7 @@ void connectHttp() { if(CON_DEBUG) Serial.println(F("Connected to Wifi network!")); - if(true) Serial.println(F("Request DHCP")); + if(CON_DEBUG) Serial.println(F("Request DHCP")); while (!cc3000.checkDHCP()) { delay(100); // ToDo: Insert a DHCP timeout! @@ -78,14 +78,11 @@ void connectHttp() { pushClient = cc3000.connectTCP(sserver, SERVICE_PORT); //SERVICE_PORT if (pushClient.connected()) { - if(true) Serial.println(F("pushClient Connected to server")); + if(CON_DEBUG) Serial.println(F("pushClient Connected to server")); } else { if(CON_DEBUG) Serial.println(F("pushClient Connection failed")); } - - - - + if(CON_DEBUG) Serial.println(F("-------------------------------------")); } @@ -148,12 +145,11 @@ bool displayConnectionDetails(void) void setupClient(){ pushClient = cc3000.connectTCP(sserver, SERVICE_PORT); //SERVICE_PORT if (pushClient.connected()) { - if(CON_DEBUG) Serial.println(F("client Connected to server")); + if(CON_DEBUG) Serial.println(F("pushClient Connected to server")); } else { while( !cc3000.checkConnected() ){ - connectHttp(); - + connectHttp(); } - if(CON_DEBUG) Serial.println(F("client Connection failed")); + if(CON_DEBUG) Serial.println(F("pushClient Connection failed")); } } diff --git a/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.h b/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.h index 59b4a9fa..178aa898 100644 --- a/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.h +++ b/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.h @@ -39,7 +39,7 @@ #define WLAN_SECURITY WLAN_SEC_WPA // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 -#define IDLE_TIMEOUT_MS 3000 +//#define IDLE_TIMEOUT_MS 3000 #define DEVICE_OWNER "${DEVICE_OWNER}" #define DEVICE_ID "${DEVICE_ID}" diff --git a/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.ino b/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.ino index bae133f2..6eb98e19 100644 --- a/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.ino +++ b/modules/distribution/src/sketches/firealarm_wifi/FireAlarmWifiAgent.ino @@ -44,11 +44,10 @@ void setup() { void loop() { - while (!cc3000.checkConnected()) { connectHttp(); - } + wdt_reset(); if (millis() - pushTimestamp > PUSH_INTERVAL) { @@ -59,6 +58,7 @@ void loop() { pushData(); pushTimestamp = millis(); } + readControls(); wdt_reset(); diff --git a/modules/distribution/src/sketches/firealarm_wifi/Listener.ino b/modules/distribution/src/sketches/firealarm_wifi/Listener.ino index b94df8c8..f78e7716 100644 --- a/modules/distribution/src/sketches/firealarm_wifi/Listener.ino +++ b/modules/distribution/src/sketches/firealarm_wifi/Listener.ino @@ -63,7 +63,8 @@ void readControls() { delay(100); // Close the connection when done. - Serial.println(F("Client disconnected")); + Serial.println(F("Listener Client disconnected")); + client.flush(); client.close(); wdt_reset(); diff --git a/modules/distribution/src/sketches/sensebot_wifi/HttpServer.ino b/modules/distribution/src/sketches/sensebot_wifi/HttpServer.ino index 972c1b7e..b0f25db0 100644 --- a/modules/distribution/src/sketches/sensebot_wifi/HttpServer.ino +++ b/modules/distribution/src/sketches/sensebot_wifi/HttpServer.ino @@ -57,6 +57,7 @@ void readControls() // Wait a short period to make sure the response had time to send before // the connection is closed (the CC3000 sends data asyncronously). delay(200); + client.flush(); client.close(); }