I'm trying to POST the data of total
, but it returns 400. but when I try a sample data like
int httpResponseCode = http.POST("{\"amount\":\"total\"}");
(400)
into
int httpResponseCode = http.POST("{\"amount\":\"15\"}");
it works (201).
How to make it work? Thanks!
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const byte interruptPin = 4;
const int interval = 500;
volatile unsigned long tiptime = millis();
volatile float rainrate = 0.3;
volatile float total;
void ICACHE_RAM_ATTR count();
void loop() {
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if (WiFi.status()== WL_CONNECTED) {
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/json");
// Data to send with HTTP POST
int httpResponseCode = http.POST("{\"amount\":\"total\"}");
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
void count() {
// Grab the current ms count for common calculations
unsigned long curtime = millis();
// Make sure we don't record bounces
if ((curtime - tiptime) < interval) {
return;
}
// How long since the last tip?
unsigned long tipcount = curtime - tiptime;
tiptime = curtime;
total += rainrate;
Serial.println(total);
}