Hello,
I've started Arduino programming today. I want to send AT commands from Arduino Mega to the Iridium 9600 (satellite modem).
If I connect Iridium directly to the computer, I can send him AT commands via serial port (Software is HTerm) and it works! Iridium sends emails. So I wrote a programm for Arduino and connected Iridium to Arduino. I'm sending the same commands, but the modem doesn't send the message via.
Can you help me? I'm really new to Arduino, to modems, to electronic, to all about this.
My programm:
String inputString;
void setup() {
Serial.begin(9600); // USB
Serial1.begin(19200); // Iridium 9600
inputString.reserve(200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
while (!Serial1) {
Serial.println("Serial1 is not ready!");
}
}
void loop() {
if (Serial.available() > 0) {
inputString = Serial.readString();
inputString.trim();
Serial.println("Input: " + inputString);
Serial.println("--- AT commands ---");
Serial.print("AT+SBDWB=");
Serial.println(getLengthOfString(inputString));
Serial1.print("AT+SBDWB=");
Serial1.println(getLengthOfString(inputString));
delay(2000);
String data = getData(inputString);
data.toUpperCase();
Serial.println(data);
Serial1.println(data);
delay(4000);
Serial.println("AT+SBDIX");
Serial1.println("AT+SBDIX");
delay(4000);
Serial.println("AT+SBDD0");
Serial1.println("AT+SBDD0");
Serial.println("--- END ---");
}
// response of Iridium
if (Serial1.available() > 0) {
String response = Serial1.readString();
Serial.println(response);
}
}
/**
Converts ASCII to HEX with 2-byte-checksum
*/
String getData(String ascii) {
int summe = 0;
String hexString;
for (int i = 0; i < ascii.length(); i++) {
int decValue = ascii[i] + 0;
summe += decValue;
String hexValue = String(decValue, HEX);
hexString = hexString + hexValue;
}
String sumHexValue = String(summe, HEX);
String checksumHex = getHexOfInt(summe, 2);
return hexString + checksumHex;
}
String getHexOfInt(int num, int precision) {
char tmp[16];
char format[128];
sprintf(format, "0%%.%dX", precision);
sprintf(tmp, format, num);
// Serial.print(tmp);
return tmp;
}
/**
It's necessary for
AT+SBDWB=<message length>
*/
int getLengthOfString(String s) {
return s.length();
}