I have a Nano+ENC28J60 and I'm using Pushingbox which I have setup to write data to a GoogleDrive spreadsheet which works perfectly at home. However when I take it to my workplace it no longer works.
At work, serial tells me that the
- Ethernet connection is good;
- I get a client connection OK too.
However, [edit] on client.read(); it reports
- only a backwards question mark.
I assume it is to do with some firewall or other restriction, but if I can get a connection that should be enough, no?
[edit] note: i have also tried connecting to port 443 instead of port 80 in case it was an HTTPS issue - same results, though]
How I can write to GDrive on my work network?
The code [edited from original 1. changed POST to GET 2. moved client.read() after GET]:
#include "DHTesp.h"
#include <SPI.h>
#include <UIPEthernet.h>
DHTesp dhtA; DHTesp dhtB;
const int ledPin = LED_BUILTIN;
int ledState = LOW;
int interval = 20; // this is the num seconds between reads (120=2mins) ***************************
int numReads = 2; // Amount of reads between posting to Gdocs. ***************************
byte mac[] = {0xAA, 0xF0, 0xDE, 0xDE, 0x06, 0xAF }; // Ethernet shield MAC addy
byte ip[] = { 10, 10, xx, yy };
char devid [] = "vXXXXXXXXXXXXXXXX"; // device ID from Pushingbox
char server[] = "http://api.pushingbox.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
Serial.println ();
Serial.print(F("Establishing..."));
if (Ethernet.begin(mac) == 0) {
Serial.println(F("Failed to configure ethernet"));
//while (true); // no point in carrying on, so do nothing forevermore
}
else {
Serial.println(F("Ethernet OK."));
// print the Ethernet board/shield's IP address:
Serial.print(F("local IP addy: "));
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a mo to initialize:
delay(3000);
Serial.println("____________________________________________"); Serial.println();
dhtA.setup(3); // sensor A
dhtB.setup(4); // sensor B
pinMode(ledPin, OUTPUT);
}
void loop(){
int Ahumidity = 0; int Atemperature = 0 ;
int Bhumidity = 0; int Btemperature = 0;
int j = 0;
for (j = 1; j <= numReads ; j++ ) {
int p = 0;
for (p = 1; p <= interval ; p++) {
delay (1000);
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) { ledState = HIGH; }
else { ledState = LOW; }
Serial.print (F("."));
digitalWrite(ledPin, ledState);
}
Serial.print (" reading: ");
Ahumidity += 10 * dhtA.getHumidity(); Atemperature += 10 * dhtA.getTemperature();
Bhumidity += 10 * dhtB.getHumidity(); Btemperature += 10 * dhtB.getTemperature();
Serial.print (j); Serial.print (F("/")); Serial.print (numReads);
Serial.println();
}
Serial.print (F("Show the averaged val.s : "));
Serial.print(F("\t\tA:")); Serial.print(Atemperature/(numReads)); Serial.print(F("\t")); Serial.print(Ahumidity/(numReads));
Serial.print (F("\tB:")); Serial.print(Btemperature/(numReads)); Serial.print(F("\t")); Serial.print(Bhumidity/(numReads));
// now connect + write to Gdrive....................
if (client.connect(server, 80)) {
Serial.println();
Serial.print(F("OK connected ... "));
client.print(F("GET /pushingbox?devid="));
client.print(devid);
client.print(F("&tempA=")); client.print(Atemperature/numReads);
client.print(F("&tempB=")); client.print(Btemperature/numReads);
client.print(F("&tempC=0&tempD=0&tempE=0&tempF=0&tempG=0&tempH=0")); // null data needed
client.print(F("&humidA=")); client.print(Ahumidity/numReads);
client.print(F("&humidB=")); client.print(Bhumidity/numReads);
client.print(F("&humidC=0&humidD=0&humidE=0&humidF=0&humidG=0&humidH=0")); //null data needed
client.print (F("&submit=Submit"));
client.println(F(" HTTP/1.1"));
//client.println(F("Host: api.pushingbox.com"));
client.println(F("Host: http://api.pushingbox.com")); // trying the addition of http://...
client.println(F("Connection: close"));
client.println();client.println();
Serial.println(F(" written. CLOSED."));
Serial.println ();
delay(1000);
//client.stop();
char c = client.read();
Serial.print (c);
}
else {
Serial.println("didnt get a connection :(");
}
}
byte ip[] = { 10, 10, xx, yy };but I seeipis not used – Juraj 2 days ago