Using a Raspberry pi to send and receive SMS texts via a HiLink 3G internet modem
NB! working but not complete!
Objectives
1)
Receive a text when there is new data or a system crash etc.
2) Request data by sending text "Report" to the HiLink USB dongle.
My land line internet speed is less tha 0.6 Mbits so I now use a 3G mobile internet link.
Huawei Unlocked E3372 LTE/4G 150 Mbps USB Dongle - HiLink - plugs into -
TP-Link TL-MR3420 4G N300 Wi-Fi Router
Huawei E3372 External Log Periodic yagi antenna connects to the HiLink
These give 7 to 12 Mbits /sec (at a price...)
But they also allow my Raspberry Pis to send my phone text messages via the web pages presented by the Hilink dongle at http://192.168.8.1/html/smsinbox.html
An SMS sent to the Pis can request a data report as an SMS reply.
So a simple mobile phone without internet access could also control and interrogate devices on my LAN.
Some early tests to see if this is possible.
Many thanks to this site
Send an SMS from a bash script
#!/bin/bash # /home/graham/SMS/command.sh # e.g. - - /home/graham/SMS/command.sh 0794xxxxx77 "test SMS from Raspberry PI" NUMBER=$1 /home/graham/SMS/session.sh LENGTH=${#MESSAGE} SMS="<request><Index>-1</Index><Phones><Phone>$NUMBER</Phone></Phones><Sca/><Content>$MESSAGE</Content><Length>$LENGTH</Length><Reserved>1</Reserved><Date>$TIME</Date></request>" echo $SMS curl -v -b /var/www/html/ramdisk2/session.txt -c /var/www/html/ramdisk2/session.txt -H "X-Requested-With: XMLHttpRequest" --data "$SMS" http://192.168.8.1/api/sms/send-sms --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml"
|
- which uses - session.sh
#!/bin/bash curl -b /var/www/html/ramdisk2/session.txt -c /var/www/html/ramdisk2/session.txt http://192.168.8.1/html/index.html > /dev/null 2>&1
|
- and token.sh
#!/bin/bash # /home/graham/SMS/token.sh TOKEN=$(curl -s -b /var/www/html/ramdisk2/session.txt -c /var/www/html/ramdisk2/session.txt http://192.168.8.1/html/smsinbox.html) echo $TOKEN > /var/www/html/ramdisk2/token.txt
|
Save the last SMS received to xml file - read1smstofile-to-ramdisk2.sh
#!/bin/sh # /home/graham/SMS/read1sms-to-ramdisk2.sh RESPONSE=`curl -s -X GET http://192.168.8.1/api/webserver/SesTokInfo` #curl -b $COOKIE -c $COOKIE -H "X-Requested-With: XMLHttpRequest" --data "$DATA" http://192.168.8.1/api/sms/sms-list --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml" |
First test of Blassic basic program "get_last_message.bas" to extract the phone number, date and message text and respond with a report if the message received is "Report"
use apt-get install xsltproc to get xsltproc to extract text from xml message file
I tried to use Blassic but some SMS have many lines and it proved difficult find the end of the message.
#!/usr/sbin/blassic '/home/graham/SMS/get_last_message.bas LABEL StartAgain PRINT "Count after StartAgain = ", count message$ = "" SHELL "/home/graham/SMS/read1sms-to-ramdisk2.sh" OPEN "/var/www/html/ramdisk2/message.txt" FOR INPUT AS #1 Label NextBit Phone$ = message$(7) FOR i = 11 to j PRINT "SMS received from ", Phone$ ," at ", Received$ PRINT "middle bit",MID$(message$, 2, 6) IF ((MID$(message$, 2, 6) = "Report") AND (count = 0)) THEN PRINT "doing something" : GOTO SendReportFile PAUSE 10000 count = 0 '** GOTO StartAgain Label SendReportFile 'if count is 1 then send a reply count = count + 1 IF count > 1 THEN GOTO StartAgain OPEN "/var/www/html/ramdisk2/i2c72temp_latest.txt" FOR INPUT AS #1 sms_report$ = "T Outside " + T_Outside$ + CHR$(10) + " T Inside " + T_PoolAir$ + CHR$(10) + " T Pool " + T_Pool$ + CHR$(10) + " Hive lb " + HivePounds$ SMS$ = "/home/graham/SMS/command.sh 079xxxxx677 " + CHR$34 + sms_report$ + CHR$34 ' NB! CHR$34 is " CHR$(10) is linefeed - so each value is printed on a new line on the phone SMS display PRINT SMS$ SHELL SMS$
|
(The report will be saved to /var/www/html/ramdisk2/sms_report.txt by other programs)
mymessage.xml looks like
<?xml version="1.0" encoding="utf-8"?> <response> <Count>1</Count> <Messages> <Message> <Smstat>0</Smstat> <Index>40029</Index> <Phone>+447941225677</Phone> <Content>Report</Content> <Date>2016-09-27 17:37:09</Date> <Sca></Sca> <SaveType>4</SaveType> <Priority>0</Priority> <SmsType>1</SmsType> </Message> </Messages> </response> |
message.txt looks like (with a better knowledge of xsltproc this could be cleaned up (but Blassic string handling is so easy!)
<?xml version="1.0"?> 1 |
transform.xsl looks like
<?xml version="1.0"?> </xsl:template> |
Please email me if you want to swap notes
apt-get install xsltproc