 ESP8266WebServer webServer(80);
 String apSSIDStr = "WaterElf-" + String(ESP.getChipId());
 const char* apSSID = apSSIDStr.c_str();
-String svrAddr = ""; // address of a local server
+String svrAddr = ""; // address of a local server TODO delete?
 
 /////////////////////////////////////////////////////////////////////////////
 // page generation stuff ////////////////////////////////////////////////////

  String toSend = genServerConfForm();
  webServer.send(200, "text/html", toSend);
}
void handle_svrchz() {
  dln(netDBG, "serving page at /svrchz");
  String toSend = pageTop;
  toSend += ": data sharing configured";

    dln(monitorDBG, "Found pH sensor");
  }
}

/*
construct and post (via GET, to confuse you), sensor data like this:

GET /collect/WaterElf-10865861 HTTP/1.1
User-Agent: WaterElf/0.000001
Host: citsci.wegrow.social:8000
Accept: application/json
Content-Type: application/json
Content-Length: 146

{ "timestamp": 39653, "airTemp": 25.90, "humidity": 49.40, "light": 8, "pH": 11.12, "waterLevel1": 257, "waterLevel2": 257, "waterLevel3": 257 }


GET /collect/9999 HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost:8000
Accept: application/json
Content-Type: application/json
Content-Length: 92

{"timestamp": 22200, "airTemp": 55, "humidity": 44, "lux": 1494, "pH": 6.4, "waterTemp": 14}
*/
void postSensorData(monitor_t *monitorData) {
  dln(citsciDBG, "\npostSensorData");
  String jsonBuf = "";
  String citsciAddr = "citsci.wegrow.social";
  formatMonitorEntry(monitorData, &jsonBuf, true);
  String envelope =
    "GET /collect/"; envelope += apSSIDStr; envelope += " HTTP/1.1\r\n";
  envelope += "User-Agent: WaterElf/0.000001\r\n";
  envelope += "Host: "; envelope += citsciAddr; envelope += ":8000\r\n";
  envelope += "Accept: application/json\r\n";
  envelope += "Content-Type: application/json\r\n";
  envelope += "Content-Length: " ;
  envelope += jsonBuf.length() + 2; // + 2 for the cr/nls
  envelope += "\r\n\r\n";
  envelope += jsonBuf;
  dln(citsciDBG, envelope);
  
  WiFiClient citsciClient;
  if(citsciClient.connect(citsciAddr.c_str(), 8000)) {
    dbg(netDBG, citsciAddr);
    dln(citsciDBG, " - connected to citsci server");
    citsciClient.print(envelope);
  } else {
    dbg(netDBG, citsciAddr);
    dln(citsciDBG, " - no citsci server");
  }

  dln(citsciDBG, "");
  return;
}
void formatMonitorEntry(monitor_t *m, String* buf, bool JSON) {
