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 :(");
    }

}
New contributor
user1778467 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You should probably ask your local network administrator. They are going to be the ones who know how they are blocking you. You have given us absolutely zero information on the corporate network so there is very little chance of us being able to help you circumvent it. – Delta_G 2 days ago
  • sure, thanks @Delta_G. i'm happy to provide whatever information i can - what question should i ask the network administrator? – user1778467 2 days ago
  • you use static IP? – Juraj 2 days ago
  • Hi @ Juraj do you mean the question to ask is: "do we use a static IP here"? if yes/no what would that mean for the sketch? thx – user1778467 2 days ago
  • I asked because you have byte ip[] = { 10, 10, xx, yy }; but I see ip is not used – Juraj 2 days ago

Your code for HTTP request has multiple issues.

After you connect to an HTTP server, it doesn't send anything until it receives your request. Your check for available bytes should always fail. Remove the if (client.available()) part, including the else part.

You make a POST request, but you put all parameters to URL and the request has no body. Change it to GET or put the parameters into request body and use "Content-type: application/x-www-form-urlencoded". Don't forget the Content-length parameter.

You send the request in very small parts. Every single print is send right away over network. Concatenate strings and print one or use buffered print.

And you should read the HTTP response and check the status.

  • some reading to content length and buffering github.com/jandrassy/StreamLib/blob/master/README.md – Juraj 2 days ago
  • Thanks Juraj. i have 1. changed POST to GET (as it should have been:) 2. concatenated the separate client.print statements as a string and now client.print all in one go. Unfortunately same result :( A question: where/how do i read HTTP response? cheers – user1778467 yesterday
  • FYI i tried char c = client.read (); Serial.print (c); after the all-in-one client.print, and i get a backwards '?' – user1778467 yesterday
  • FYI#2 i also tried if (client.connect(server, 443) { in case it was a HTTPS issue... gives exactly the same results :( – user1778467 yesterday
  • see WebClient on example how to prin response. use available() – Juraj yesterday

Your Answer

user1778467 is a new contributor. Be nice, and check out our Code of Conduct.
 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.