I have a MKR NB 1500. I have successfully used the example program SendSMS to send a text message to my phone. Step 1.
I have also successfully made a simple Arduino cloud/dashboard program that allows me to update values on the dashboard as well as controlling an LED on the board from the dashboard. Step 2.
I would appreciate some guidance on how to combine the functions of both of these programs so I can send an SMS from my Arduino cloud program. I am not sure just how to do this.
here are my thoughts: The cloud program uses the SARA modem on the board to sync the variables with the dashboard etc using MQTT in the background, and the SendSMS program would need to use the same modem to send the SMS.
I think there must need to be some way to suspend the MQTT variable syncing so that the modem can send the SMS, and then resume the variable syncing.
I doubt the modem can be used for both functions at the same time, since it has one serial interface to communicate with the modem.
Has anyone done this before?
As a simple example, from the dashboard a switch is activated, which causes an SMS to be sent to a phone with a message.
I'm also wondering how to send an "AT" command to the modem when the cloud program has already opened the serial port for the modem?
I appreciate any insight as to how to do this. Thanks.
Don't mind. The modem can open several tcp sockets. Sending a sms is a mobile network thing. The capacity of the serial AT console is not the bottleneck. The modem is a fully computer with os, ram etc. You communicate over a serial console with the AT commands from "your" computer, the arduino, to another computer. BUT: There is no debuging on the modem, you have to wait wait for the modem's answer and so on. You can't predict the behaviour of the modem due to it's dependence to the mobile network. This is the hard part: Handle the modem with it's unpredictable behaviour. Sounds probably strange but you will see...
I understand what you are saying. I understand how the modem works with AT commands. I have used the serial passthrough program and manually sent SMS using the AT commands.
I also have looked at the example code that uses sockets and mostly understand it.
The IoT cloud program, in the background, is using the modem AT commands to update the "Thing" variables. As far as I can tell, there is no way to suspend that process so an SMS can be sent, and then start it up again so the Thing variables and dashboards can be updated.
I haven't been able to figure out a way (in code) to open a path to the modem from a cloud program to communicate with the modem. Using parts fro the send SMS example program cause all kinds of errors.
For example, the cloud program, in the background, is using the modem sending AT commands to sync the Thing cloud variables at random times. I can't just barge in and send AT commands to send an SMS in the middle of all that. It seems you must send the modem an AT command and then wait for the response for that command before sending the next command. If there was a way to suspend the sync process after it's last AT command has replied, Then I could send an SMS and somehow resume the sync process.
I also have not been successful in doing anything like Modem.begin(115200); or Modem.print("ATxxxx") or how to receive the response from the modem. Any ideas there?
I really appreciate the help. I could figure it out if I knew how to communicate with the modem while the Thing variables/dashboards are syncing without messing things up
Yes. I reduced everything to MQTT. Set up a Mosquito MQTT broker, attached a node client that writes the values to a DB, send out the SMS over a API to a professional SMS gateway.
So: Arduino<---(MQTT)--->Mosquito Broker<--(MQTT)--->Node Server<---->DB<---->Grafana for Visualize and Node---->Routee.net as a SMS Gateway.
To Communicate to the Arduino i subscribe to a MQTT Topic and have two way communication this way. Work stable for years now with MKR1010 (Over WiFi), MKR1400 and MKR1500 over modem (2G/3G/4G).
OK, Thanks for the explanation. I had thought about trying something
like that, but it is a bit beyond my knowledge at this time.
I wanted to use Arduino's IoT cloud with their Dashboards. So that was
the basis of my original question, How to send an SMS from within their
cloud/dashboard framework.
I understand I could do it other ways like you did. You essentially
wrote your own version of Arduino's IoT cloud and dashboards.
I do want to learn how to use MQTT for future projects.
It appears that using the automatically generated code as a starting
point, and use their dashboard system, severely limits what you can
do. At least I have yet to find an example of how to use the modem for
any other purpose when using the cloud and dashboard setup Arduino is
selling. Not ready for prime time yet. Sad, it has potential.