I would like to connect several of my Arduino MKR GSM 1400s to a raspberry pi 3b+. The arduinos would be sending a temperature and a pressure over a cellular network periodically, say every 30 minutes. The RPi would need to receive the values with a timestamp and store it in a MYSQL database.
I have tested/verified the connection with the cellular carrier with my Arduinos, but I am unsure of what communication protocol and the best method to make the connection between the Pi and Arduino? Does anyone have some experience with this?
The simplest solution (Since the Arduino is not a good device for a TCP/IP stack) is to use the MKR GSM to send SMS messages, containing your readings. Then read these at the rPi end, and process them.
I’d probably send a text (SMS) message from one GSM (or 4G or whatever cell phone network) module to the other as already suggested. That should be easy enough.
If you just use the audio channel, it gets much more complicated, but would also be possible. You’d use AFSK or similar.
Another option may be to use an internet based MySQL service (LAMP server etc.) so the units transmitting the data directly load the data into a database using, for example, http put transactions. You may even be able to expose your rpi (configured say as a LAMP server) to the Internet. This could be cheaper especially if some of the transmitting units are in range of a wlan.
I can give the SMS a try but I will need to do some reading.
But on the lamp server comment, I just set up an apache web server on the pi with a MYSQL database. Will the MKR GSM be able to write directly to this MYSQL database? And if so is this possible for more than one arduino?
If you rpi is configured with an Apache, php and MySQL application and is exposed to the Internet (you have a public IP address/ a router port forwarding rule) then it can be accessed by anyone on the Internet. They simply use a web browser and give your server and a path to the application as the url.
If you have a cell phone module and a data subscription, you have access to the Internet so can access the rpi configured as above. Your Arduino with cellphone module becomes a web client of the rpi just like any web browser. It can simply issue http get/put commands like a web browser does in the background.
An Apache server can manage multiple simultaneous connections. But anyway your transactions will be of very short duration.
feynman137:
What about the Arduino hinders the TCP protocol use versus a RPi?
Hi,
I tried various implementations of TCP/IP on an Arduino some years ago, and I concluded it's not really up to the job. (Not enough RAM, lack of threading O/S, etc.) I know it can be done, but I had a lot of trouble getting it to maintain a TCP/IP connection.
It may well be that the Arduino has improved, especially with things like the Mega, so feel free to disregard my potentially outdated views
For my own projects, in house, I use a node consisting of an Arduino with attached temperature sensors to monitor a hot water tank, and also act as a timer for the hot water, and measure power consumption. This sends data (Over serial port) to an attached Pi, which does the heavy lifting. (It parses the data, and broadcasts MQTT messages, which are picked up and collated / stored by a central computer). Over-engineering at its best, but great fun!
greycon:
Hi,
I tried various implementations of TCP/IP on an Arduino some years ago, and I concluded it's not really up to the job. (Not enough RAM, lack of threading O/S, etc.) I know it can be done, but I had a lot of trouble getting it to maintain a TCP/IP connection.
It may well be that the Arduino has improved, especially with things like the Mega, so feel free to disregard my potentially outdated views
For my own projects, in house, I use a node consisting of an Arduino with attached temperature sensors to monitor a hot water tank, and also act as a timer for the hot water, and measure power consumption. This sends data (Over serial port) to an attached Pi, which does the heavy lifting. (It parses the data, and broadcasts MQTT messages, which are picked up and collated / stored by a central computer). Over-engineering at its best, but great fun!
The Arduinos have moved on a bit from 8bit "2009" and Unos with only 2k of RAM. The one that the OP is looking at Arduino MKR GSM 1400 — Arduino Official Store is a 32 bit MCU with 32k of RAM.
If there is a wireless LAN nearby, the ESP8266 and ESP32 devices are usually a good option to consider and very cheap.
Thanks for the comment Greycon. I built a DIY E61 espresso machine whose sensors are monitored by an UNO which is attached serially to a PI, which does the heavy lifting like you said. Although I am not doing any data transmitting, it was a memory issue with the UNO.
But let me ask you guys this is the GSM MKR up to the task of being a reliable web client with its hardware ..etc? Or would it be necessary to do this with a PI with a cellular module. It is not a lot of data maybe, 5 integers sent every 30 minutes.
As a side note cellular is the only option for the project, because it will be on a farm in the middle of nowhere!
Lora was designed for this type of application with long range, low bandwidth data applications where latency is not an issue. But that depends also on what is available in your area. You can even create Lora nodes for others to use (at least here).
Using a cell phone network could be expensive. Apart from the hardware, you have to consider the cell phone network data plans you have locally.
I have no personal experience with the MKR GSM 1400 but I guess it works as designed. Again, the network infrastructure depends on the location. Here, all the old network technologies are being phased out. 4G will probably be here for a few years.
This is where it starts getting out of the hobby area. You are talking about multiple nodes sending data to a central server and I guess you'll be interested in achieving this in a cost effective way.
If Lora is not an option, I'd also be looking also at using standard cell phones with a Bluetooth adapter for the data transmission part. Important there is that you have the power consumption aspects under control, like shutting them down when not in use etc.
Okay very interesting. It sounds like Lora might be a better option just because I can control my own network coverage, versus cellular. Seems like the gateway costs a little bit but can host multiple devices.
I know I am off the original topic here, but with say a Pi with a Lora shield connected to a gateway I would still be issuing HTTP get/put commands to the LAMP server right? The only change is the network, or would this change com protocols ..etc?
So would coms be:
Device (Uno, Pi, or ESP32) -> MQTT Broker (Pi) -> LAMP server