switch to unencrypted API
This commit is contained in:
parent
e9cbe78ff1
commit
ceab2f70bd
1 changed files with 5 additions and 12 deletions
17
api.h
17
api.h
|
@ -1,25 +1,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClient.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "streampipe.h"
|
#include "streampipe.h"
|
||||||
|
|
||||||
class OsemApi {
|
class OsemApi {
|
||||||
protected:
|
protected:
|
||||||
WiFiClientSecure client;
|
WiFiClient client;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool postMeasurement(String measurement, String sensorID) {
|
bool postMeasurement(String measurement, String sensorID) {
|
||||||
if (!client.connect(API_ENDPOINT, 443)) {
|
if (!client.connect(API_ENDPOINT, 8000)) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!client.verify(API_FINGERPRINT, API_ENDPOINT)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
client << String("POST ") << "/boxes/" << ID_BOX << "/" << sensorID << " HTTP/1.1" << EOL;
|
client << String("POST ") << "/boxes/" << ID_BOX << "/" << sensorID << " HTTP/1.1" << EOL;
|
||||||
client << "Host: " << API_ENDPOINT << EOL;
|
client << "Host: " << API_ENDPOINT << EOL;
|
||||||
client << "X-APIKey: " << API_KEY << EOL;
|
|
||||||
client << "Content-Type: application/json" << EOL;
|
client << "Content-Type: application/json" << EOL;
|
||||||
client << "Connection: close" << EOL;
|
client << "Connection: close" << EOL;
|
||||||
client << "Content-Length: " << measurement.length() << EOL << EOL;
|
client << "Content-Length: " << measurement.length() << EOL << EOL;
|
||||||
|
@ -29,7 +22,7 @@ class OsemApi {
|
||||||
if (!client.connected()) return false;
|
if (!client.connected()) return false;
|
||||||
String line = client.readStringUntil('\r');
|
String line = client.readStringUntil('\r');
|
||||||
if (line != "HTTP/1.1 201 Created") return false;
|
if (line != "HTTP/1.1 201 Created") return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue