0

Sensors values:

float temperature = 29.5;
float humidity = 32.56;
float lightLevel = 17365.83;
int co2 = 452;
int noise = 583;

String dataString  = ""+String(temperature)+","+String(humidity)+","+String(lightLevel)+","+String(co2)+","+String(noise)+"";

The String will look like: "29.50,32.56,17365.83,452,583"

The hexstring would look like: "32392e35302c33322e35362c31373336352e38332c3435322c353833aa"

The modem I use will only accept AT commands and requires the data payload to be

payload in hexadecimal format strings (maximum length is 242 bytes)

Example Command: AT+SEND=1:1:32392e35302c33322e35362c31373336352e38332c3435322c353833aa

I am unable to create "AT+SEND=1:1:32392e35302c33322e35362c31373336352e38332c3435322c353833aa" programmatically in the Arduino.

How do you convert the dataString to the hexstring?

1
  • Where does aa at the end of the hexstring come from? It's not part of the original string. Commented Jun 24, 2024 at 18:15

1 Answer 1

0

You can make the serial interface convert string characters into their hexadecimal value representation.

void at_send(Print &serial, int port, int ack, String data) {
    serial.print("AT+SEND=");
    serial.print(port);
    serial.print(':');
    serial.print(ack);
    serial.print(':');
    for (int i=0; i<data.length(); i++) {
        if (data[i] < 16) { // ensure 2 characters per byte
            serial.print('0');
        } 
        serial.print(data[i], HEX);
    }
    serial.print("\r\n");
}

// then call as
at_send(Serial, 1, 1, dataString);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.