Raspberry Pi Module GSM SIM800
14 septembre 2016 à 15:32
Bonjour,
Je vous propose aujourd'hui un test complet sur un module GSM, ainsi qu'un ensemble d'indication sur sont utilisation avec Node-Red et Gammu. Le module provient de mon partenaire GearBest que vous trouverez ICI.
Présentation du module
J'ai choisi le module GSM SIM800 essentiellement pour un projet futur, un de mes autres passe-temps est l’aéromodélisme, et sur certaine piste de vol il existe des balises qui permettes, avec l'envoi d'un sms sur une borne de récupérer les informations telle que le vent, température ...
Avant de ce lancer dans la programmation d'un balise météo, il faut comprendre le module GSM. Ce dernier fonction avec une carte SIM standard (Je précise car il est de plus en plus rare d'en trouver), il est alimenté directement via la Raspberry Pi mais si votre alimentation est trop faible il est possible d'alimenter directement le module.
Ce module est aussi pourvut d'un prise jack pour les appelles ainsi qu'une prise micro, je n'ai pas essayer le mode téléphone de ce module et je ne pense pas à l'utilisé pour le moment.
Les commandes AT
Le module est connecté au Raspberry Pi via le port série, une fois le port ouvert ont peu envoyer toutes les commandes AT nécessaires. Le protocole AT est un protocole couramment utilisé dans le monde du Télécom, il permet facilement d'accéder à toutes les fonctionnalités.
J'ai dans un premier temps avant d'utiliser Gammu fait des bouts de programme en utilisant directement les commandes AT. Par exemple pour rentrer le code PIN de la carte la commande est :
AT+CPIN="0000"
La commande pour connaitre l'état du code pin(réponse OK ou ERROR):
AT+CPIN?
Si vous souhaitez vous intéressé de plus prés aux commandes AT je vous suggère le site suivant, qui fournit des exemples de codes pour tous les usages :
https://www.cooking-hacks.com/documentation/tutorials/gprs-gsm-quadband-module-arduino-raspberry-pi-tutorial-sim-900/
Pour ma part, je me suis vite tourné vers une application qui fait le lien directement avec la gestion de SMS.
Gammu et Node-Red
Comme décrit ci-dessus, j'ai vite décidé d'utilisé une applications reconnu dans le domaine des SMS sur Linux. Gammu permet après configuration d’envoyer et de recevoir simplement via des fichiers texte des SMS, coupler ensuite avec un outils aussi facile d'utilisation que Node-Red il permet de créer facilement un serveur de SMS. Ont pourra ensuite imaginé de contrôler les GPIO par SMS etc ...
Je ne tient pas à faire un tutoriel complet sur l'installation des configurations de Gammu et Node-Red car d'autre avant moi l'ont fait et même trés bien fait, par contre je vous laisse les liens qui mon servis. Je donnerais seulement mon Flow Node-Red pour les personnes intéresser.
Configuration de Gammu :
- http://milillicuti.com/raspberry-pi-et-sms/ (Surtour deuxiéme partie "Envoyer des SMS")
Node-Red et Gammu :
Mon flow
Mon Flow et une reproduction du tutoriel que vous trouverez ci-dessus, à la différence que j'y ai ajouté un redirection de SMS.
Ont peut ensuite imaginé l'ajout en base des SMS reçus, mais aussi et ont en revient à mon idée de début d'ajouter des capteurs d'humidité, de température. Pour que lorsque que l'ont reçois un SMS quelconque, la balise nous redirige un SMS avec les informations des différents capteurs.
Le flow à intégrer :
[{"id":"ddbf4a2b.6511e8","type":"watch","z":"40f7c618.a3ed08","name":"SMS Inbox","files":"/var/spool/gammu/inbox","x":95,"y":140,"wires":[["94b60042.6f946"]]},{"id":"df2ec96b.a0a328","type":"file in","z":"40f7c618.a3ed08","name":"SMS Content","filename":"","format":"utf8","x":509,"y":140,"wires":[["7e6d2d3.d9163d4"]]},{"id":"94b60042.6f946","type":"change","z":"40f7c618.a3ed08","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":295,"y":140,"wires":[["df2ec96b.a0a328"]]},{"id":"7e6d2d3.d9163d4","type":"function","z":"40f7c618.a3ed08","name":"","func":"msg.phone = msg.filename.match(/(\\+[0-9]*)/)[1];\nmsg.msg = msg.payload;\ndelete msg.filename;\ndelete msg.topic;\ndelete msg.file;\ndelete msg.type;\nreturn msg;","outputs":1,"noerr":0,"x":701,"y":139,"wires":[["3cfba985.2578e6","cece9f04.b40a3"]]},{"id":"3cfba985.2578e6","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"msg","x":881,"y":139,"wires":[]},{"id":"79036263.6172dc","type":"comment","z":"40f7c618.a3ed08","name":"Réception SMS","info":"Réception SMS","x":110,"y":71,"wires":[]},{"id":"aed6d996.4f4638","type":"comment","z":"40f7c618.a3ed08","name":"Envoi de SMS","info":"Envoi de SMS","x":95,"y":363,"wires":[]},{"id":"bee6def3.0359e","type":"http in","z":"40f7c618.a3ed08","name":"","url":"/SendSMS","method":"get","swaggerDoc":"","x":106,"y":426,"wires":[["71630f38.296cd"]]},{"id":"71630f38.296cd","type":"template","z":"40f7c618.a3ed08","name":"prepare SMS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"gammu-smsd-inject TEXT \"{{payload.phone}}\" -text \"{{payload.msg}}\"","x":308,"y":427,"wires":[["32cdb709.a67208","dba0df9b.0f1d4"]]},{"id":"32cdb709.a67208","type":"exec","z":"40f7c618.a3ed08","command":"","addpay":true,"append":"","useSpawn":"","timer":"","name":"Exec gammu","x":498,"y":426.5,"wires":[["8b6181a2.a8ca2"],[],[]]},{"id":"8b6181a2.a8ca2","type":"switch","z":"40f7c618.a3ed08","name":"Check rerponse","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Created outbox message","vt":"str"},{"t":"neq","v":"Created outbox message","vt":"str"}],"checkall":"false","outputs":2,"x":702,"y":413,"wires":[["8e1f15cc.132bb8"],["291e95a6.b58fba"]]},{"id":"8e1f15cc.132bb8","type":"function","z":"40f7c618.a3ed08","name":"OK","func":"msg.payload = \"OK\";\nreturn msg;","outputs":1,"noerr":0,"x":876,"y":395,"wires":[["77d203bd.0255ec"]]},{"id":"291e95a6.b58fba","type":"function","z":"40f7c618.a3ed08","name":"KO","func":"msg.payload=\"ko\";\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":451,"wires":[["77d203bd.0255ec"]]},{"id":"77d203bd.0255ec","type":"http response","z":"40f7c618.a3ed08","name":"Reponse","x":1055,"y":424,"wires":[]},{"id":"a0c270dd.87e9c","type":"comment","z":"40f7c618.a3ed08","name":"Redirection","info":"","x":408,"y":250,"wires":[]},{"id":"ff5de49c.222fb8","type":"exec","z":"40f7c618.a3ed08","command":"","addpay":true,"append":"","useSpawn":"","timer":"","name":"Exec gammu","x":713,"y":291,"wires":[["7860e813.3c6998"],[],[]]},{"id":"7860e813.3c6998","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"false","x":897,"y":278,"wires":[]},{"id":"cece9f04.b40a3","type":"function","z":"40f7c618.a3ed08","name":"","func":"msg.payload = \"gammu-smsd-inject TEXT +33669937230 -text \" + msg.msg\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":292,"wires":[["ff5de49c.222fb8"]]},{"id":"dba0df9b.0f1d4","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"false","x":489,"y":531,"wires":[]}]
[{"id":"ddbf4a2b.6511e8","type":"watch","z":"40f7c618.a3ed08","name":"SMS Inbox","files":"/var/spool/gammu/inbox","x":95,"y":140,"wires":[["94b60042.6f946"]]},{"id":"df2ec96b.a0a328","type":"file in","z":"40f7c618.a3ed08","name":"SMS Content","filename":"","format":"utf8","x":509,"y":140,"wires":[["7e6d2d3.d9163d4"]]},{"id":"94b60042.6f946","type":"change","z":"40f7c618.a3ed08","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":295,"y":140,"wires":[["df2ec96b.a0a328"]]},{"id":"7e6d2d3.d9163d4","type":"function","z":"40f7c618.a3ed08","name":"","func":"msg.phone = msg.filename.match(/(\\+[0-9]*)/)[1];\nmsg.msg = msg.payload;\ndelete msg.filename;\ndelete msg.topic;\ndelete msg.file;\ndelete msg.type;\nreturn msg;","outputs":1,"noerr":0,"x":701,"y":139,"wires":[["3cfba985.2578e6","cece9f04.b40a3"]]},{"id":"3cfba985.2578e6","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"msg","x":881,"y":139,"wires":[]},{"id":"79036263.6172dc","type":"comment","z":"40f7c618.a3ed08","name":"Réception SMS","info":"Réception SMS","x":110,"y":71,"wires":[]},{"id":"aed6d996.4f4638","type":"comment","z":"40f7c618.a3ed08","name":"Envoi de SMS","info":"Envoi de SMS","x":95,"y":363,"wires":[]},{"id":"bee6def3.0359e","type":"http in","z":"40f7c618.a3ed08","name":"","url":"/SendSMS","method":"get","swaggerDoc":"","x":106,"y":426,"wires":[["71630f38.296cd"]]},{"id":"71630f38.296cd","type":"template","z":"40f7c618.a3ed08","name":"prepare SMS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"gammu-smsd-inject TEXT \"{{payload.phone}}\" -text \"{{payload.msg}}\"","x":308,"y":427,"wires":[["32cdb709.a67208","dba0df9b.0f1d4"]]},{"id":"32cdb709.a67208","type":"exec","z":"40f7c618.a3ed08","command":"","addpay":true,"append":"","useSpawn":"","timer":"","name":"Exec gammu","x":498,"y":426.5,"wires":[["8b6181a2.a8ca2"],[],[]]},{"id":"8b6181a2.a8ca2","type":"switch","z":"40f7c618.a3ed08","name":"Check rerponse","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Created outbox message","vt":"str"},{"t":"neq","v":"Created outbox message","vt":"str"}],"checkall":"false","outputs":2,"x":702,"y":413,"wires":[["8e1f15cc.132bb8"],["291e95a6.b58fba"]]},{"id":"8e1f15cc.132bb8","type":"function","z":"40f7c618.a3ed08","name":"OK","func":"msg.payload = \"OK\";\nreturn msg;","outputs":1,"noerr":0,"x":876,"y":395,"wires":[["77d203bd.0255ec"]]},{"id":"291e95a6.b58fba","type":"function","z":"40f7c618.a3ed08","name":"KO","func":"msg.payload=\"ko\";\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":451,"wires":[["77d203bd.0255ec"]]},{"id":"77d203bd.0255ec","type":"http response","z":"40f7c618.a3ed08","name":"Reponse","x":1055,"y":424,"wires":[]},{"id":"a0c270dd.87e9c","type":"comment","z":"40f7c618.a3ed08","name":"Redirection","info":"","x":408,"y":250,"wires":[]},{"id":"ff5de49c.222fb8","type":"exec","z":"40f7c618.a3ed08","command":"","addpay":true,"append":"","useSpawn":"","timer":"","name":"Exec gammu","x":713,"y":291,"wires":[["7860e813.3c6998"],[],[]]},{"id":"7860e813.3c6998","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"false","x":897,"y":278,"wires":[]},{"id":"cece9f04.b40a3","type":"function","z":"40f7c618.a3ed08","name":"","func":"msg.payload = \"gammu-smsd-inject TEXT +33669937230 -text \" + msg.msg\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":292,"wires":[["ff5de49c.222fb8"]]},{"id":"dba0df9b.0f1d4","type":"debug","z":"40f7c618.a3ed08","name":"","active":true,"console":"false","complete":"false","x":489,"y":531,"wires":[]}]
Conclusion
Ce shield est de très bonne facture, facile d'utilisation car n'est pas relier au Raspberry Pi via un bus tel que SPI ou I2C mais via le port UART. Les pins GPIO sont toujours disponible pour ajouter des capteurs etc.
Tout de même gourmand en énergie, car souvent l'alimentation du Raspberry Pi ne suffisait pas. Dernier gros intérêt ce sont les commandes AT qui permet de ne pas avoir de librairie propriétaire pour communiquer avec les puces GSM.
Je reste à votre disposition si vous avez besoins d'autres renseignements concernant le fonctionnement, ou si vous avez un projet avec une shield GSM.