Commit 275d3cd7 authored by PhiBo's avatar PhiBo 🚀

Use uuid and api key to submit values

parent d08de7c5
......@@ -35,6 +35,14 @@ uint8_t ArduRPC_SensorNode::call(uint8_t cmd_id)
if(WiFi.status() != WL_CONNECTED) {
connectWiFiClient(1);
}
// get Params UUID and API KEY
this->gatParam_string(&this->sensor_uuid[0], SENSOR_NODE_UUID_MAX_LENGTH);
this->sensor_uuid[SENSOR_NODE_UUID_MAX_LENGTH] = '\0';
this->gatParam_string(&this->sensor_key[0], SENSOR_NODE_KEY_MAX_LENGTH);
this->sensor_uuid[SENSOR_NODE_KEY_MAX_LENGTH] = '\0';
this->status = 2;
this->cache->reset();
this->cache->print("[");
......@@ -136,10 +144,13 @@ void ArduRPC_SensorNode::submitData()
getAPIHostnameOrDefault(&hostname[0], NODE_EEPROM_API_HOSTNAME_MAX_LENGTH);
client->println("POST /sensor/data");
client->print("POST /sensors/");
client->print(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->print("Content-Length: ");
client->println(this->cache->length);
client->println();
......
......@@ -31,6 +31,8 @@
#define NODE_API_DEFAULT_HOSTNAME ""
#define SENSOR_NODE_UUID_MAX_LENGTH 64
#define SENSOR_NODE_KEY_MAX_LENGTH 64
class DataString : public Print
{
......@@ -54,6 +56,8 @@ class ArduRPC_SensorNode : public ArduRPCHandler
private:
uint8_t status;
DataString *cache;
char sensor_uuid[SENSOR_NODE_UUID_MAX_LENGTH + 1];
char sensor_key[SENSOR_NODE_UUID_MAX_LENGTH + 1];
};
void ICACHE_FLASH_ATTR handleAPIHostname();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment