void ArduRPC_SensorNode::submitData()
{
  uint16_t i;
  char hostname[NODE_EEPROM_API_HOSTNAME_MAX_LENGTH + 1];
  uint16_t port;

  if(this->status != 4) {
    return;
  }

  if(WiFi.status() != WL_CONNECTED) {
    return;
  }

/*
  if(connectSensorAPI() == false) {
    return;
  }
*/
  getAPIHostnameOrDefault(&hostname[0], NODE_EEPROM_API_HOSTNAME_MAX_LENGTH);
  port = getAPIPortOrDefault();

  HTTPClient http;

  String path;
  path.reserve(64);
  path = "/sensors/";
  path += this->sensor_uuid;

  http.begin(hostname, port, path);
  http.addHeader("X-Sensor-Api-Key", this->sensor_key);
  http.addHeader("X-Sensor-Version", "1");
  int code;
  code = http.POST(this->cache.data, this->cache.length);
  NODE_DEBUG_PRINT("Code ");
  NODE_DEBUG_PRINTLN(code);

  // ToDo: validate code
  this->status = 0;

/*
  client.print("POST /sensors/");
  client.println(this->sensor_uuid);
  client.print("Host: ");
  client.println(hostname);
  client.println("Connection: close");
  client.print("X-Sensor-Api-Key: ");
  client.println(this->sensor_key);
  client.println("X-Sensor-Version: 1");
  client.print("Content-Length: ");
  client.println(this->cache.length);
  client.println();
  for(i = 0; i < this->cache.length; i++) {
    Serial.print((char)this->cache.data[i]);
  }
  this->status = 0;
  client.stop();
*/
}
void ICACHE_FLASH_ATTR ThingSpeakClass::SendThingSpeakValues()
{

	//  if (ThingEnabled) DebugPrintln("thingspeak enabled"); else DebugPrintln("thingspeak disabled");                   
	if (ThingEnabled == false) return;
	if (thingSpeakURL == "") return;
	DebugPrintln(thingSpeakURL);

	if (WiFi.status() != WL_CONNECTED) return;   //check to make sure we are connected...	  

	String postStr = "api_key=" + thingWriteKey;
	if (HMGlobal.hmPitTemp != "U")  postStr += "&field1=" + HMGlobal.hmPitTemp;
	if (HMGlobal.hmFood1 != "U") postStr += "&field2=" + HMGlobal.hmFood1;
	if (HMGlobal.hmFood2 != "U") postStr += "&field3=" + HMGlobal.hmFood2;
	if (HMGlobal.hmAmbient != "U") postStr += "&field4=" + HMGlobal.hmAmbient;
	if (HMGlobal.hmFanMovAvg != "U") postStr += "&field5=" + HMGlobal.hmFanMovAvg;
	if (HMGlobal.hmFan != "U") postStr += "&field6=" + HMGlobal.hmFan;
	if (HMGlobal.hmSetPoint != "U") postStr += "&field7=" + HMGlobal.hmSetPoint;
	if (HMGlobal.hmLidOpenCountdown != "U") postStr += "&field8=" + HMGlobal.hmLidOpenCountdown;

	if (inAlarm)  //if alarm was triggered we send on next msg
	{
		postStr += "&status=" + MyWebServer.urlencode(MyWebServer.CurTimeString() + " " + AlarmInfo);
		AlarmInfo = "";
		inAlarm = false;
	}

		
		HTTPClient http;
		
		DebugPrintln("http://" + thingSpeakURL + "/update");
		http.begin("http://" + thingSpeakURL + "/update");

		int httpCode = http.POST(postStr);

		// httpCode will be negative on error
		if (httpCode > 0) {
			if (httpCode == HTTP_CODE_OK) {				
			}
		}
		else {
			DebugPrintln("[HTTP] POST... failed, error: " + http.errorToString(httpCode));
		}
		http.end();
		
		
	DebugPrintln("sending thingspeak stuffs");

}
Example #3
0
void loop() {
  String url = "http://things.ubidots.com/api/v1.6/variables/" ID_VARIABLE "/values";
  http.begin(url);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("X-Auth-Token", AUTH_TOKEN);
  int content_length =0;
  String payload = String("{ \"value\": " + String(millis()/1000) + "}");
  //content_length = payload.length();
  //http.addHeader("Content-Length", String(content_length));
  int httpCode = http.POST(payload);
  if(httpCode > 0) {
    String payload = http.getString();
    Serial.println(payload);
  }
  else {
    Serial.print("[HTTP] failed, error: ");Serial.println(http.errorToString(httpCode).c_str());
  }
  http.end();
  delay(20000);
}