|
|
@ -1,10 +1,15 @@
|
|
|
|
void pushDigitalPinData(){
|
|
|
|
|
|
|
|
for ( int pin = 0; pin < (sizeof(digitalPins)/sizeof(int)); pin++) {
|
|
|
|
/**********************************************************************************************
|
|
|
|
String payLoad = jsonPayLoad + "DigitalPinData";
|
|
|
|
This method will traverse the array of digital pins and batch the data from the those pins together.
|
|
|
|
payLoad = payLoad + "\",\"time\":\"" + "9999";
|
|
|
|
It makes a single call to the server and sends all pin values as a batch.
|
|
|
|
payLoad = payLoad + "\",\"key\":\"" + getDataType(digitalPins[pin]);
|
|
|
|
Server dis-assembles it accordingly and makes multiple publish calls for each sensor type.
|
|
|
|
payLoad = payLoad + "\",\"value\":\"";
|
|
|
|
***********************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pushData(){
|
|
|
|
|
|
|
|
String payLoad = "Data";
|
|
|
|
|
|
|
|
payLoad = payLoad + "\",\"value\":\"";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( int pin = 0; pin < (sizeof(digitalPins)/sizeof(int)); pin++) {
|
|
|
|
if ( digitalPins[pin] == TEMP_PIN ) {
|
|
|
|
if ( digitalPins[pin] == TEMP_PIN ) {
|
|
|
|
int temperature = (uint8_t)getTemperature();
|
|
|
|
int temperature = (uint8_t)getTemperature();
|
|
|
|
payLoad += temperature;
|
|
|
|
payLoad += temperature;
|
|
|
@ -13,20 +18,25 @@ void pushDigitalPinData(){
|
|
|
|
} else if ( digitalRead(digitalPins[pin]) == LOW ) {
|
|
|
|
} else if ( digitalRead(digitalPins[pin]) == LOW ) {
|
|
|
|
payLoad += "OFF";
|
|
|
|
payLoad += "OFF";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ((sizeof(digitalPins)/sizeof(int)) - 1) != pin ) {
|
|
|
|
|
|
|
|
payLoad += "-";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
payLoad += "\"}";
|
|
|
|
payLoad += "\"}";
|
|
|
|
|
|
|
|
|
|
|
|
httpClient.fastrprint(F("POST "));
|
|
|
|
pushClient.fastrprint(F("POST "));
|
|
|
|
httpClient.fastrprint(SERVICE_EPOINT); httpClient.fastrprint(F("pushalarmdata"));
|
|
|
|
pushClient.fastrprint(SERVICE_EPOINT); pushClient.fastrprint(F("pushalarmdata"));
|
|
|
|
httpClient.fastrprint(F(" HTTP/1.1")); httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(F(" HTTP/1.1")); pushClient.fastrprint(F("\n"));
|
|
|
|
httpClient.fastrprint(host.c_str()); httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(host.c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
httpClient.fastrprint(F("Content-Type: application/json")); httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(F("Content-Type: application/json")); pushClient.fastrprint(F("\n"));
|
|
|
|
httpClient.fastrprint(F("Content-Length: "));
|
|
|
|
pushClient.fastrprint(F("Content-Length: "));
|
|
|
|
|
|
|
|
|
|
|
|
int payLength = payLoad.length();
|
|
|
|
int payLength = jsonPayLoad.length() + payLoad.length();
|
|
|
|
|
|
|
|
|
|
|
|
httpClient.fastrprint(String(payLength).c_str()); httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(String(payLength).c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
|
|
|
|
if(DEBUG) {
|
|
|
|
if(DEBUG) {
|
|
|
|
Serial.print("POST ");
|
|
|
|
Serial.print("POST ");
|
|
|
@ -41,25 +51,38 @@ void pushDigitalPinData(){
|
|
|
|
|
|
|
|
|
|
|
|
int chunkSize = 50;
|
|
|
|
int chunkSize = 50;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < payLength; i++) {
|
|
|
|
for (int i = 0; i < jsonPayLoad.length(); i++) {
|
|
|
|
if ( (i+1)*chunkSize > payLength) {
|
|
|
|
if ( (i+1)*chunkSize > jsonPayLoad.length()) {
|
|
|
|
httpClient.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
pushClient.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
|
|
|
|
i = payLength;
|
|
|
|
i = jsonPayLoad.length();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
httpClient.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
pushClient.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < payLoad.length(); i++) {
|
|
|
|
|
|
|
|
if ( (i+1)*chunkSize > payLoad.length()) {
|
|
|
|
|
|
|
|
pushClient.print(payLoad.substring(i*chunkSize, payLoad.length()));
|
|
|
|
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLoad.length()));
|
|
|
|
|
|
|
|
i = payLoad.length();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
pushClient.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
httpClient.fastrprint(F("\n"));
|
|
|
|
pushClient.fastrprint(F("\n"));
|
|
|
|
if(DEBUG) Serial.println();
|
|
|
|
if(DEBUG) Serial.println();
|
|
|
|
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
|
|
|
|
while (httpClient.available()) {
|
|
|
|
if(true) {
|
|
|
|
char response = httpClient.read();
|
|
|
|
while (pushClient.available()) {
|
|
|
|
if(DEBUG) Serial.print(response);
|
|
|
|
char response = pushClient.read();
|
|
|
|
|
|
|
|
if(DEBUG) Serial.print(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(DEBUG) {
|
|
|
|
if(DEBUG) {
|
|
|
@ -68,73 +91,188 @@ void pushDigitalPinData(){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
payLoad = "";
|
|
|
|
payLoad = "";
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pushAnalogPinData(){
|
|
|
|
/**********************************************************************************************
|
|
|
|
for ( int pin = 0; pin < (sizeof(analogPins)/sizeof(int)); pin++) {
|
|
|
|
This method will traverse the array of digital pins and publish the data from the those pins.
|
|
|
|
String payLoad = jsonPayLoad + "AnalogPinData";
|
|
|
|
It differs from the above method such that the pin data is published one after the other in
|
|
|
|
payLoad = payLoad + "\",\"time\":\"" + "9999";
|
|
|
|
seperate calls to the server
|
|
|
|
payLoad = payLoad + "\",\"key\":\"" + getDataType(analogPins[pin]);
|
|
|
|
***********************************************************************************************/
|
|
|
|
payLoad = payLoad + "\",\"value\":\"" + analogRead(analogPins[pin]);
|
|
|
|
|
|
|
|
payLoad = payLoad + "\"}";
|
|
|
|
|
|
|
|
|
|
|
|
//void pushDigitalPinData(){
|
|
|
|
httpClient.fastrprint(F("POST "));
|
|
|
|
// for ( int pin = 0; pin < (sizeof(digitalPins)/sizeof(int)); pin++) {
|
|
|
|
httpClient.fastrprint(SERVICE_EPOINT); httpClient.fastrprint(F("pushalarmdata"));
|
|
|
|
// String payLoad = getDataType(digitalPins[pin]);
|
|
|
|
httpClient.fastrprint(F(" HTTP/1.1")); httpClient.fastrprint(F("\n"));
|
|
|
|
// payLoad = payLoad + "\",\"value\":\"";
|
|
|
|
httpClient.fastrprint(host.c_str()); httpClient.fastrprint(F("\n"));
|
|
|
|
//
|
|
|
|
httpClient.fastrprint(F("Content-Type: application/json")); httpClient.fastrprint(F("\n"));
|
|
|
|
// if ( digitalPins[pin] == TEMP_PIN ) {
|
|
|
|
httpClient.fastrprint(F("Content-Length: "));
|
|
|
|
// int temperature = (uint8_t)getTemperature();
|
|
|
|
|
|
|
|
// payLoad += temperature;
|
|
|
|
int payLength = payLoad.length();
|
|
|
|
// } else if ( digitalRead(digitalPins[pin]) == HIGH ) {
|
|
|
|
|
|
|
|
// payLoad += "ON";
|
|
|
|
httpClient.fastrprint(String(payLength).c_str()); httpClient.fastrprint(F("\n"));
|
|
|
|
// } else if ( digitalRead(digitalPins[pin]) == LOW ) {
|
|
|
|
httpClient.fastrprint(F("\n"));
|
|
|
|
// payLoad += "OFF";
|
|
|
|
|
|
|
|
// }
|
|
|
|
if(DEBUG) {
|
|
|
|
//
|
|
|
|
Serial.print("POST ");
|
|
|
|
// payLoad += "\"}";
|
|
|
|
Serial.print(SERVICE_EPOINT); Serial.print("pushalarmdata");
|
|
|
|
//
|
|
|
|
Serial.print(" HTTP/1.1"); Serial.println();
|
|
|
|
// pushClient.fastrprint(F("POST "));
|
|
|
|
Serial.print(host); Serial.println();
|
|
|
|
// pushClient.fastrprint(SERVICE_EPOINT); pushClient.fastrprint(F("pushalarmdata"));
|
|
|
|
Serial.print("Content-Type: application/json"); Serial.println();
|
|
|
|
// pushClient.fastrprint(F(" HTTP/1.1")); pushClient.fastrprint(F("\n"));
|
|
|
|
Serial.print("Content-Length: ");
|
|
|
|
// pushClient.fastrprint(host.c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
Serial.print(payLength); Serial.println();
|
|
|
|
// pushClient.fastrprint(F("Content-Type: application/json")); pushClient.fastrprint(F("\n"));
|
|
|
|
Serial.println();
|
|
|
|
// pushClient.fastrprint(F("Content-Length: "));
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
// int payLength = jsonPayLoad.length() + payLoad.length();
|
|
|
|
int chunkSize = 50;
|
|
|
|
//
|
|
|
|
|
|
|
|
// pushClient.fastrprint(String(payLength).c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
for (int i = 0; i < payLength; i++) {
|
|
|
|
// pushClient.fastrprint(F("\n"));
|
|
|
|
if ( (i+1)*chunkSize > payLength) {
|
|
|
|
//
|
|
|
|
httpClient.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
// if(DEBUG) {
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
// Serial.print("POST ");
|
|
|
|
i = payLength;
|
|
|
|
// Serial.print(SERVICE_EPOINT); Serial.print("pushalarmdata");
|
|
|
|
} else {
|
|
|
|
// Serial.print(" HTTP/1.1"); Serial.println();
|
|
|
|
httpClient.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
// Serial.print(host); Serial.println();
|
|
|
|
if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
// Serial.print("Content-Type: application/json"); Serial.println();
|
|
|
|
}
|
|
|
|
// Serial.print("Content-Length: ");
|
|
|
|
}
|
|
|
|
// Serial.print(payLength); Serial.println();
|
|
|
|
|
|
|
|
// Serial.println();
|
|
|
|
httpClient.fastrprint(F("\n"));
|
|
|
|
// }
|
|
|
|
if(DEBUG) Serial.println();
|
|
|
|
//
|
|
|
|
|
|
|
|
// int chunkSize = 50;
|
|
|
|
delay(1000);
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (int i = 0; i < jsonPayLoad.length(); i++) {
|
|
|
|
while (httpClient.available()) {
|
|
|
|
// if ( (i+1)*chunkSize > jsonPayLoad.length()) {
|
|
|
|
char response = httpClient.read();
|
|
|
|
// pushClient.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
|
|
|
|
if(DEBUG) Serial.print(response);
|
|
|
|
// if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
|
|
|
|
}
|
|
|
|
// i = jsonPayLoad.length();
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
if(DEBUG) {
|
|
|
|
// pushClient.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
Serial.println();
|
|
|
|
// if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
Serial.println("-------------------------------");
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
payLoad = "";
|
|
|
|
// for (int i = 0; i < payLoad.length(); i++) {
|
|
|
|
delay(1000);
|
|
|
|
// if ( (i+1)*chunkSize > payLoad.length()) {
|
|
|
|
|
|
|
|
// pushClient.print(payLoad.substring(i*chunkSize, payLoad.length()));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLoad.length()));
|
|
|
|
|
|
|
|
// i = payLoad.length();
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// pushClient.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.println();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// delay(1000);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(true) {
|
|
|
|
|
|
|
|
// while (pushClient.available()) {
|
|
|
|
|
|
|
|
// char response = pushClient.read();
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(response);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(DEBUG) {
|
|
|
|
|
|
|
|
// Serial.println();
|
|
|
|
|
|
|
|
// Serial.println("-------------------------------");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// payLoad = "";
|
|
|
|
|
|
|
|
//// delay(1000);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************************************
|
|
|
|
|
|
|
|
Only required for cases of reading analog pin values.
|
|
|
|
|
|
|
|
An int Array of analog pins that needs to be read has to be initialised.
|
|
|
|
|
|
|
|
This method will traverse the array and publish the data from the selected pins
|
|
|
|
|
|
|
|
***********************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//void pushAnalogPinData(){
|
|
|
|
|
|
|
|
// for ( int pin = 0; pin < (sizeof(analogPins)/sizeof(int)); pin++) {
|
|
|
|
|
|
|
|
// String payLoad = jsonPayLoad + "AnalogPinData";
|
|
|
|
|
|
|
|
// payLoad = payLoad + "\",\"time\":\"" + "9999";
|
|
|
|
|
|
|
|
// payLoad = payLoad + "\",\"key\":\"" + getDataType(analogPins[pin]);
|
|
|
|
|
|
|
|
// payLoad = payLoad + "\",\"value\":\"" + analogRead(analogPins[pin]);
|
|
|
|
|
|
|
|
// payLoad = payLoad + "\"}";
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("POST "));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(SERVICE_EPOINT); pushClient.fastrprint(F("pushalarmdata"));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F(" HTTP/1.1")); pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(host.c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("Content-Type: application/json")); pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("Content-Length: "));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// int payLength = payLoad.length();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// pushClient.fastrprint(String(payLength).c_str()); pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(DEBUG) {
|
|
|
|
|
|
|
|
// Serial.print("POST ");
|
|
|
|
|
|
|
|
// Serial.print(SERVICE_EPOINT); Serial.print("pushalarmdata");
|
|
|
|
|
|
|
|
// Serial.print(" HTTP/1.1"); Serial.println();
|
|
|
|
|
|
|
|
// Serial.print(host); Serial.println();
|
|
|
|
|
|
|
|
// Serial.print("Content-Type: application/json"); Serial.println();
|
|
|
|
|
|
|
|
// Serial.print("Content-Length: ");
|
|
|
|
|
|
|
|
// Serial.print(payLength); Serial.println();
|
|
|
|
|
|
|
|
// Serial.println();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// int chunkSize = 50;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (int i = 0; i < payLength; i++) {
|
|
|
|
|
|
|
|
// if ( (i+1)*chunkSize > payLength) {
|
|
|
|
|
|
|
|
// pushClient.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLength));
|
|
|
|
|
|
|
|
// i = payLength;
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// pushClient.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// pushClient.fastrprint(F("\n"));
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.println();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// delay(1000);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(true) {
|
|
|
|
|
|
|
|
// while (pushClient.available()) {
|
|
|
|
|
|
|
|
// char response = pushClient.read();
|
|
|
|
|
|
|
|
// if(DEBUG) Serial.print(response);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(DEBUG) {
|
|
|
|
|
|
|
|
// Serial.println();
|
|
|
|
|
|
|
|
// Serial.println("-------------------------------");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// payLoad = "";
|
|
|
|
|
|
|
|
// delay(1000);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getDataType(int pin){
|
|
|
|
|
|
|
|
switch(pin){
|
|
|
|
|
|
|
|
case TEMP_PIN:
|
|
|
|
|
|
|
|
return "TEMP";
|
|
|
|
|
|
|
|
case BULB_PIN:
|
|
|
|
|
|
|
|
return "BULB";
|
|
|
|
|
|
|
|
case FAN_PIN:
|
|
|
|
|
|
|
|
return "FAN";
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return String(pin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|