hi im rookie
i buy Grove-Laser_PM2.5_Sensor-HM3301 im try edit code new format for keep in var and return value. but it error cant convert to string
//start hm3301
HM330X sensor;
uint8_t buf[30];
const char *str[] = {"sensor num: ", "PM1.0 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM2.5 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM10 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM1.0 concentration(Atmospheric environment,unit:ug/m3): “,
“PM2.5 concentration(Atmospheric environment,unit:ug/m3): “,
“PM10 concentration(Atmospheric environment,unit:ug/m3): “,
};
HM330XErrorCode print_result(const char *str, uint16_t value) {
char newformat;
if (NULL == str) {
return ERROR_PARAM;
}
//SERIAL_OUTPUT.print(str);
//SERIAL_OUTPUT.println(value);
newformat = str + “=” + value;
return newformat;
//return NO_ERROR;
}
//parse buf with 29 uint8_t-data
HM330XErrorCode parse_result(uint8_t *data) {
uint16_t value = 0;
char resultpm;
if (NULL == data)
return ERROR_PARAM;
for (int i = 1; i < 8; i++) {
value = (uint16_t) data[i * 2] << 8 | data[i * 2 + 1];
//print_result(str[i - 1], value);
resultpm += print_result(str[i - 1], value);
if(i < 7){
resultpm += “, “;
}
}
return resultpm;
//return NO_ERROR;
}
HM330XErrorCode parse_result_value(uint8_t *data) {
if (NULL == data) {
return ERROR_PARAM;
}
for (int i = 0; i < 28; i++) {
//SERIAL_OUTPUT.print(data[i], HEX);
//SERIAL_OUTPUT.print(” “);
if ((0 == (i) % 5) || (0 == i)) {
//SERIAL_OUTPUT.println(””);
}
}
uint8_t sum = 0;
for (int i = 0; i < 28; i++) {
sum += data[i];
}
if (sum != data[28]) {
SERIAL_OUTPUT.println(“wrong checkSum!!!”);
}
//SERIAL_OUTPUT.println(””);
return NO_ERROR;
}
//end hm3301
void loop() {
//hm3301
//parse_result_value(buf);
//parse_result(buf);
//SERIAL_OUTPUT.println(””);
String postData = sensorName + “,sensorType=BME680 temperature=” + t + “,pressure=” + p + “,humidity=” + h + “,gas=” + g;
int httpCode = http.POST(postData);
SERIAL_OUTPUT.print(httpCode);
SERIAL_OUTPUT.print(” : ");
SERIAL_OUTPUT.println(postData);
String postData2 = sensorName + “,sensorType=HM3301 " + parse_result(buf); <<< i want to send this format style
int httpCode2 = http.POST(postData2);
SERIAL_OUTPUT.print(httpCode2);
SERIAL_OUTPUT.print(” : ");
SERIAL_OUTPUT.println(postData2);
}
Anyone help me please. ty so much Anyone.