Following is the zabbix documentation with the query header format. Document Zabbix
I have difficulty implementing this header in C ++ (Arduino),
I saw an implementation of what I need in this forum here , however it is in Russian and is implemented in C #, I tried to translate it but to no avail.
So I need someone to help me write the function of the header examples in C ++ (Arduino).
Follows full Arduino code after @EdgarBonet change suggestion
#include <ArduinoJson.h>
#include <SPI.h>
#include <Ethernet.h>
// Config IP
IPAddress ip(192, 168, 0, 130);
IPAddress gw(192, 168, 0, 1);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
float contador = 0;
EthernetClient client;
//Config Server address
const char* server = "192.168.0.135";
int porta = 10051;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
}
void loop() {
// Begin Json
const size_t capacity = JSON_ARRAY_SIZE(1)
+ JSON_OBJECT_SIZE(2)
+ JSON_OBJECT_SIZE(3);
DynamicJsonBuffer jsonBuffer(capacity);
JsonObject& root = jsonBuffer.createObject();
root["request"] = "sender data";
JsonArray& data = root.createNestedArray("data");
JsonObject& data_0 = data.createNestedObject();
data_0["host"] = "ethernet";
data_0["key"] = "variavel1";
data_0["value"] = contador;
String json = "";
root.printTo(json);
const uint8_t *dataSend = (const uint8_t *) json.c_str();
uint64_t data_length = json.length();
uint8_t packet[13 + data_length]; // 13-byte header + payload
// Write the 5-byte signature.
memcpy(packet, "ZBXD\1", 5);
// Add the 8-byte packet length, LSB first.
for (int i = 0; i < 8; i++) {
packet[5+i] = data_length >> 8*i;
}
// Add the payload.
memcpy(packet + 13, dataSend, data_length);
if (client.connect(server, porta)) {
Serial.println("Enviando ao servidor");
delay(1000);
// Send the packet.
client.write(packet, sizeof packet);
delay(1000);
contador ++;
}
}
Following server response:
2034:20191003:101411.196 Message size 2066888786 from 192.168.0.130 exceeds the maximum size 1073741824 bytes. Message ignored.