0

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] even with 5 attempts at a response client.read(); it reports nothing at all. Serial shows

OK connected! Written. Checking response: + + + + + 

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 [edit#2 modified client.connect() to try 5 times and a response check via client.read() to try 5 times and Serial.print("+ "); each time] :

#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;

int c = '\0';

void setup()
{
  Serial.begin(9600);
  Serial.println ();

  Serial.print(F("dB_CoSdataV3.  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 second to initialize:
  delay(3000);

  Serial.println("____________________________________________");  Serial.println();

  dhtA.setup(3); //  sensor A
  dhtB.setup(4); //  sensor B
  //dhtC.setup(7); dhtD.setup(7);

  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....................
  boolean connected;
  int counter1 = 0;
  do {
      connected = client.connect(server, 80);
      if (connected) { break; }
      client.stop();
      delay(1000);
      Serial.println("retry");
      counter1++;
  } while (!connected && counter1 <5);


//------------------
//if (client.connect(server, 80)) {

if (connected){
    Serial.println();
    Serial.print(F("OK connected! "));   

      String buf;

      buf += F("GET /pushingbox?devid=");
      buf += String(devid);

      buf += F("&tempA=");  buf += String(Atemperature/numReads);
      buf += F("&tempB=");  buf += String(Btemperature/numReads);
      buf += F("&tempC=0&tempD=0&tempE=0&tempF=0&tempG=0&tempH=0"); // null data needed

      buf += F("&humidA=");  buf += String (Ahumidity/numReads);
      buf += F("&humidB=");  buf += String (Bhumidity/numReads);
      buf += F("&humidC=0&humidD=0&humidE=0&humidF=0&humidG=0&humidH=0"); //null data needed



      buf += F("&submit=Submit");
      buf += F(" HTTP/1.1");
      //client.println(F("Host: api.pushingbox.com"));
      buf += F("Host: http://api.pushingbox.com"); // trying the addition of http://...
      buf += F("Connection: close\r\n");
      //client.println();

      client.print(buf);
      Serial.print(F(" Written. "));
      delay(1000);   
      int counter2 = 0;
      Serial.print ("Checking response: ");

      do {
          if (client.available()) {
              Serial.print("Y ");
              c = client.read();
              Serial.print((char)c);
          }         
          delay(2000);
          Serial.print("+ ");
          counter2++;
      } while (counter2 < 5);

      Serial.println ();       Serial.println ();
      //client.stop();     
  }


}
  • 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 Oct 31 '18 at 3:57
  • sure, thanks @Delta_G. i'm happy to provide whatever information i can - what question should i ask the network administrator? – user1778467 Oct 31 '18 at 4:41
  • you use static IP? – Juraj Oct 31 '18 at 5:34
  • 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 Oct 31 '18 at 6:19
  • I asked because you have byte ip[] = { 10, 10, xx, yy }; but I see ip is not used – Juraj Oct 31 '18 at 6:36
0

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 Oct 31 '18 at 6:52
  • 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 Nov 1 '18 at 1:02
  • FYI i tried char c = client.read (); Serial.print (c); after the all-in-one client.print, and i get a backwards '?' – user1778467 Nov 1 '18 at 1:16
  • FYI#2 i also tried if (client.connect(server, 443) { in case it was a HTTPS issue... gives exactly the same results :( – user1778467 Nov 1 '18 at 3:46
  • see WebClient on example how to prin response. use available() – Juraj Nov 1 '18 at 5:40

Your Answer

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.