1
I need help sending a HEADER
, produced in Arduino (C++)
, and sent to a server Zabbix
.
Header documentation
https://www.zabbix.com/documentation/devel/manual/appendix/protocols/header_datalen
My Code in C++
Serial.println(json);
int tamanho = json.length();
String pacote = "";
pacote = "ZBXD\1" ;
String stringtres = String(pacote, BIN);
String stringOne = String(, BIN);
String separador = "\0\0\0\0";
pacote += stringOne;
pacote += separador;
pacote += json;
String stringtwo = String(pacote.length(), BIN);
Serial.println(stringtwo);
//Aqui conecto no servidor zabbix porta 10051
if(client.connect(server, porta)){
Serial.println(pacote);
client.print(pacote);
contador++;
delay(5000);
}
Example of how the code should be done in JAVA
byte[] header = new byte[] {
'Z', 'B', 'X', 'D', '\1',
(byte)(data.length & 0xFF),
(byte)((data.length >> 8) & 0xFF),
(byte)((data.length >> 16) & 0xFF),
(byte)((data.length >> 24) & 0xFF),
'\0', '\0', '\0', '\0'};
byte[] packet = new byte[header.length + data.length];
System.arraycopy(header, 0, packet, 0, header.length);
System.arraycopy(data, 0, packet, header.length, data.length);
I think I’m making this headline wrong, if anyone can help me I’m grateful!
Correct I managed to implement Header, you know how I do this concatenation, I tried to do here but without success.
code 
byte[] packet = new byte[header.length + data.length];

System.arraycopy(header, 0, packet, 0, header.length);

System.arraycopy(data, 0, packet, header.length, data.length);

– Venicius Back
You will need to Instantiate an array of
char
calledpacket
with the length of[len(data) + len(header)]
and use the methodmemcpy
to copy intopacket
the arrayheader
anddata
.– gorn
If you accept the answer, the Zabbix header will work better and better.
– gorn