Hi Raphael,
yes, I mean PUT in /recource-logs/{id}. I´m pretty sure that I´m using right URL, because I did not make any changes from point that I made it work.
Thx for info that it worked around date 13.5 so I load backup file from 12.5.2018 to be sure that I did not touch it and result is still the same.
I made separate sketch in Arduino with one heartbeat & one send request to check that I´m not crazy and also to see if heartbeat get response from server.
I´m using ESP32
Here is my Arduino code (without sensitive data):
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <SimpleTimer.h>
WiFiMulti wifiMulti;
SimpleTimer wifiTimer;
int lockVersion = 1;
int filament_used = 17574; // dummy value
String file_name = "test.gcode"; // test name
int configVersion = 0;
const char* root_ca = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" \
"GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \
"AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" \
"q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" \
"SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" \
"Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" \
"a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n" \
"/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n" \
"AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n" \
"CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n" \
"bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n" \
"c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" \
"VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" \
"ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" \
"MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" \
"Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" \
"AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \
"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \
"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \
"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \
"-----END CERTIFICATE-----\n";
const String API_key = "";
const String API_key_user = "";
int currentSessionId = 132913;
int test = 0;
WiFiClient client;
HTTPClient http;
void setup() {
Serial.begin(115200);
Serial.println("Starting..");
wifiMulti.addAP("FabLab", "wearemakers");
wifiMulti.addAP("FabLab", "wearemakers");
Serial.println("Connecting Wifi...");
if (wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("WiFi not connected");
}
wifiTimer.setInterval(5000, connection);
}
void loop() {
// put your main code here, to run repeatedly:
wifiTimer.run();
}
void connection() {
int status = WiFi.status();
if ((test != 1) && (status == WL_CONNECTED)) {
heartBeat();
log_resources();
}
if (status != WL_CONNECTED) {
wifiMulti.run();
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
}
void heartBeat() {
String heartMessage = "";
heartMessage += "{\"configVersion\":";
heartMessage += configVersion;
heartMessage += "}";
char heartMessageChar[heartMessage.length() + 1];
heartMessage.toCharArray(heartMessageChar, heartMessage.length() + 1);
http.begin("https://fabman.io/api/v1/bridge/heartbeat", root_ca ); //Specify destination for HTTP request
http.addHeader("Content-Type", "application/json"); //Specify content-type header
http.addHeader("Accept", "application/json");
http.addHeader("Authorization", API_key);
int httpResponseCode = http.POST(heartMessageChar); //Send the actual POST request
Serial.println();
Serial.println("Sending hearbeat..");
Serial.println(heartMessageChar);
String payload = http.getString();
Serial.println("JSON from server:");
Serial.println(payload);
Serial.println();
if (httpResponseCode > 0) {
Serial.print("Responde code: ");
Serial.println(httpResponseCode); //Print return code
} else {
Serial.print("Error on sending request: ");
Serial.println(httpResponseCode);
}
http.end(); //Free resources
}
void log_resources() {
String dataMessage = "";
dataMessage += "{\"metadata\":{\"Filament used\":";
dataMessage += filament_used;
dataMessage += ",\"File name\":\"";
dataMessage += file_name;
dataMessage += "\"},\"lockVersion\":";
dataMessage += lockVersion;
dataMessage += "}";
char dataMessageChar[dataMessage.length() + 1];
dataMessage.toCharArray(dataMessageChar, dataMessage.length() + 1);
Serial.println();
Serial.println("Section: log_resources");
Serial.println(dataMessage);
http.begin("https://fabman.io/api/v1/resource-logs/" + int(currentSessionId), root_ca ); //Specify destination for HTTP request
http.addHeader("Content-Type", "application/json"); //Specify content-type header
http.addHeader("Accept", "application/json");
http.addHeader("Authorization", API_key_user);
int httpResponseCode = http.PUT(dataMessage);
if (httpResponseCode > 0) {
Serial.print("Responde code: ");
Serial.println(httpResponseCode); //Print return code
Serial.println();
}
String payload = http.getString();
Serial.println("JSON from server:");
Serial.println(payload);
Serial.println();
test = 1;
}
Here is response from device when this code run (without sensitive data):
⸮х⸮ѥ⸮⸮⸮.
Connecting Wifi...
E (93) wifi: esp_wifi_scan_start 967 wifi not start
WiFi not connected
WiFi connected
IP address:
0.0.0.0
WiFi connected
IP address:
172.18.15.193
Sending hearbeat..
{"configVersion":0}
JSON from server:
{"config":{"type":1,"name":"Test","maxOfflineUsage":null,"deadManIntervalBusy":180,"deadManIntervalIdle":0,"lightWarningSeconds":30,"soundWarningSeconds":15,"inputConfig":[{"type":"none","state":true},{"type":"none","state":true},{"type":"none","state":true}],"auxEquipment":"none","exhaustErrorShutdown":false,"safetyMessage":"","offlineKeys":,"idlePowerThreshold":0,"preventPowerOffWhileBusy":false,"muteDeadMan":false,"stopAfterBusy":false,"configVersion":4261890858}}
Responde code: 200
Section: log_resources
{"metadata":{"Filament used":17574,"File name":"test.gcode"},"lockVersion":3}
JSON from server:
Sorry if I overlooked something.
Thanks for your help.
Miroslav