I am working on a small project where I intend to control some equipment with an sms message. Some of the equipment is some distance from the Master controller. I have a 3G GSM module on top of an Arduino Leonardo. I also have a HC-12 module and a relay module running on the same base.
I have set up and tested the 3G GSM module to control some equipment local to the Master controller. It all works perfectly well. An sms is received and with some conditional statements I can operate the relays.
Independently I have tested an HC-12 network from the Master controller to two slave controllers some distance away (40 m and 80 m). Transmit and receive codes seem to work well.
Transmit function is a simple print (or write) using software serial. Receive script reads the individual bytes and accumulates them. When finished the code is copied into a string variable. Both shown below.
Separately the scripts work fine but when combined the HC-12 transmit code crashes the 3G GSM.
I am using the FONA library to run the 3G GSM module. Any .print or . write command to the Software.Serial HC-12 leads to a loss of the GSM connection. To restart the connection I have to power the unit down and reboot.
Has anyone had any experience with running a 3G GSM module and an HC-12 (or any other) radio network?
Any other ideas would be welcome.
HC12.print(ControlMessage);
//Receive function
void get_message()
{
while (HC12.available()) { // While Arduino's HC12 soft serial rx buffer has data
HC12ByteIn = HC12.read(); // Store each character from rx buffer in byteIn
HC12ReadBuffer += char(HC12ByteIn); // Write each character of byteIn to HC12ReadBuffer
if (HC12ByteIn == '\n') { // At the end of the line
HC12End = true; // Set HC12End flag to true
}
}
if (HC12End) { // If HC12End flag is true
//Serial.print(HC12ReadBuffer); // Send message to screen. Not required handle in loop
ControlMessage = HC12ReadBuffer; // Store temporary message as control message
ControlMessage.replace("\n",""); // Remove new line command from string
HC12ReadBuffer = ""; // Empty buffer
HC12End = false; // Reset flag
}
}```