Community discussions

MikroTik App
 
Joshiii
newbie
Topic Author
Posts: 29
Joined: Wed May 20, 2009 10:13 am

Script on RB411U to check credit on 3G connection

Fri Apr 13, 2012 3:20 pm

Hi

I am not good with scripting at all, but I want to have a script to dial 131 (Namibia prepaid 3G) once a week, receive the the credit balance and mail me the details.

many thanks

OK, I have added /tool sms send usb4 "131" message="1" to scripts and it works, I am now looking at how to email the results to me.
 
makkan
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Mon Jul 26, 2010 12:38 am

Re: Script on RB411U to check credit on 3G connection

Fri Apr 13, 2012 5:13 pm

Hi,

This script has some file read/write operations in it. Maybe you can come up with something from that :)

http://wiki.mikrotik.com/wiki/Dynamic_D ... behind_NAT

There's also a mail client in the Mikrotik so you could do something like

1. Read sms response value
2. Put it in the email directly or put it in a text-file
3. Send an email with the value or textfile
 
Joshiii
newbie
Topic Author
Posts: 29
Joined: Wed May 20, 2009 10:13 am

Re: Script on RB411U to check credit on 3G connection

Fri Apr 13, 2012 5:40 pm

Hi

That is my problem, I do not know the command to read the sms response and write it to a text file to mail, or alternatively to sms it to another number
 
makkan
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Mon Jul 26, 2010 12:38 am

Re: Script on RB411U to check credit on 3G connection

Fri Apr 13, 2012 5:48 pm

http://wiki.mikrotik.com/wiki/Manual:Tools/Sms

http://wiki.mikrotik.com/wiki/Send_Backup_email

There you have two very useful wiki-pages, however I don't have any 3G enabled router available so I can't make any tests for you :(
 
Base122
just joined
Posts: 10
Joined: Tue Mar 13, 2012 4:28 pm

Re: Script on RB411U to check credit on 3G connection

Sun Apr 15, 2012 12:21 am

This script should help.
I have it working on a RB751 with 3G modem.
You can schedule this script at regular intervals.
Remember to set up /tools/email
# Script to forward SMS from GSM Modem Inbox to Email #
# Note: The SMS is removed from the inbox after being sent to Email, #
# even if the Email fails to be sent #
# Remember to set up /Tools/SMS with the USB port of your #
# Modem and the info channel. Put anything in secret and #
# make sure Receive Enabled is ticked #
# Tested on Rb751U RouterOS v5.12 with Huawei E367 #
# Peter James 2012-04-04 #


:local EmailAddress "your_email_address";
:local smsPhone;
:local smsTimeStamp;
:local smsMessage;
:local smsContent;

# Get System Identity #
:local SystemID [/system identity get name];

:log info "SMS to Email script started";

# Set Receive Enabled, in case it was cleared by a router reboot #
/tool sms set receive-enabled=yes;

delay 2;

# loop through all the messages in the inbox #
:foreach i in=[/tool sms inbox find] do={

:set smsPhone [/tool sms inbox get $i phone];
:set smsTimeStamp [/tool sms inbox get $i timestamp];
:set smsMessage [/tool sms inbox get $i message];

:set smsContent "Router ID: $SystemID\nSMS Received from: $smsPhone\nDate&Time: $smsTimeStamp\nMessage: $smsMessage";

:log info $smsContent;

/tool e-mail send tls=yes subject="$SystemID GSM Modem SMS Received" to=$EmailAddress body="$smsContent";

# Now remove the SMS from the inbox #
/tool sms inbox remove $i;

delay 10;

}

# clear Receive Enabled, so info channel can be used by other scripts #
/tool sms set receive-enabled=no;

:log info "SMS to Email script complete";
 
Joshiii
newbie
Topic Author
Posts: 29
Joined: Wed May 20, 2009 10:13 am

Re: Script on RB411U to check credit on 3G connection

Mon Apr 16, 2012 9:17 am

Great

Thanks to Base122, it is working like a charm.
 
Joshiii
newbie
Topic Author
Posts: 29
Joined: Wed May 20, 2009 10:13 am

Re: Script on RB411U to check credit on 3G connection

Mon Apr 16, 2012 5:11 pm

I have now created this script to forward a sms from the RB to the 3G data provider to recharge my credit.
I need help however to only forward a sms in the inbox from a certain number, (and if it contains nothing, do nothing) other wise it might forward everything in the inbox to the Cellular provider. (Most of this was provided by Base122)

# Set Receive Enabled, in case it was cleared by a router reboot #
/tool sms set receive-enabled=yes;

:local smsPhone;
:local smsContent;

:log info "SMS to ReCharge script started";

delay 2;

# loop through all the messages in the inbox #
:foreach i in=[/tool sms inbox find] do={

:set smsPhone [/tool sms inbox get $i phone];
:set smsTimeStamp [/tool sms inbox get $i timestamp];
:set smsMessage [/tool sms inbox get $i message];

:set smsContent "\nMessage: $smsMessage";

:log info $smsContent;

/tool sms send usb4 "132" message="$smsContent";

# Now remove the SMS from the inbox #
/tool sms inbox remove $i;

delay 10;

}


:log info "SMS to ReCharge script complete";
 
Joshiii
newbie
Topic Author
Posts: 29
Joined: Wed May 20, 2009 10:13 am

Re: Script on RB411U to check credit on 3G connection

Tue Apr 17, 2012 10:02 am

This script will check the inbox for a sms voucher (Format is *123443211234#) sent by me. it will forward this message to "132" (Namibia recharge number) delete the sms, receive the recharge message from the cell provider and mail it to me.
I set the script to run every 30 min, if there is no sms in the inbox it simply will not send anything as the message body is empty. Remember to change your email server settings, usb settings (for your modem) as well as your email address.

Most of this was provided by Base122



# Set Receive Enabled, in case it was cleared by a router reboot #
/tool sms set receive-enabled=yes;

delay 2;

:local smsMessage;
:local smsContent;

:log info "SMS to ReCharge script started";

delay 2;

# loop through all the messages in the inbox #
:foreach i in=[/tool sms inbox find] do={

:set smsMessage [/tool sms inbox get $i message];

:set smsContent "\nMessage: $smsMessage";

:log info $smsContent;

/tool sms send usb4 "132" message="$smsContent";

# Now remove the SMS from the inbox #
/tool sms inbox remove $i;

delay 10;

}

:local EmailAddress "123@jj.com";
:local smsPhone;
:local smsTimeStamp;
:local smsMessage;
:local smsContent;

# Get System Identity #
:local SystemID [/system identity get name];

:log info "SMS to Email script started";

delay 10;

# loop through all the messages in the inbox #
:foreach i in=[/tool sms inbox find] do={

:set smsPhone [/tool sms inbox get $i phone];
:set smsTimeStamp [/tool sms inbox get $i timestamp];
:set smsMessage [/tool sms inbox get $i message];

:set smsContent "Router ID: $SystemID\nSMS Received from: $smsPhone\nDate&Time: $smsTimeStamp\nMessage: $smsMessage";

:log info $smsContent;

/tool e-mail send tls=yes subject="$SystemID GSM Modem SMS Received" to=$EmailAddress body="$smsContent";

# Now remove the SMS from the inbox #
/tool sms inbox remove $i;

delay 10;

}

:log info "SMS to ReCharge script complete";
 
giuse1910
just joined
Posts: 1
Joined: Mon Apr 23, 2012 12:15 am

Re: Script on RB411U to check credit on 3G connection

Mon Apr 23, 2012 12:18 am

i have tryed this script in system>script and run it manually but it don't work and i don't know why ....
if i try to put it in the terminal .. it reply to me with this error


[admin@MikroTik] > # Note: The SMS is removed from the inbox after being sent to Email, #
[admin@MikroTik] > # even if the Email fails to be sent #
[admin@MikroTik] > # Remember to set up /Tools/SMS with the USB port of your #
[admin@MikroTik] > # Modem and the info channel. Put anything in secret and #
[admin@MikroTik] > # make sure Receive Enabled is ticked #
[admin@MikroTik] > # Tested on Rb751U RouterOS v5.12 with Huawei E367 #
[admin@MikroTik] > # Peter James 2012-04-04 #
[admin@MikroTik] >
[admin@MikroTik] >
[admin@MikroTik] > :local EmailAddress "info@techdigital.it";
[admin@MikroTik] > :local smsPhone;
[admin@MikroTik] > :local smsTimeStamp;
[admin@MikroTik] > :local smsMessage;
[admin@MikroTik] > :local smsContent;
[admin@MikroTik] >
[admin@MikroTik] > # Get System Identity #
[admin@MikroTik] > :local SystemID [/system identity get name];
[admin@MikroTik] >
[admin@MikroTik] > :log info "SMS to Email script started";
[admin@MikroTik] >
[admin@MikroTik] > # Set Receive Enabled, in case it was cleared by a router reboot #
[admin@MikroTik] > /tool sms set receive-enabled=yes;
[admin@MikroTik] >
[admin@MikroTik] > delay 2;
[admin@MikroTik] >
[admin@MikroTik] > # loop through all the messages in the inbox #
[admin@MikroTik] > :foreach i in=[/tool sms inbox find] do={
{...
{... :set smsPhone [/tool sms inbox get $i phone];
expected variable name (line 3 column 6)
[admin@MikroTik] > :set smsTimeStamp [/tool sms inbox get $i timestamp];
expected variable name (line 1 column 6)
[admin@MikroTik] > :set smsMessage [/tool sms inbox get $i message];
expected variable name (line 1 column 6)
[admin@MikroTik] >
[admin@MikroTik] > :set smsContent "Router ID: $SystemID\nSMS Received from: $smsPhone\nDate&Time: $smsTimeStamp\nMessage: $smsMessage";
expected variable name (line 1 column 6)
[admin@MikroTik] >
[admin@MikroTik] > :log info $smsContent;
syntax error (line 1 column 12)
[admin@MikroTik] >
[admin@MikroTik] > /tool e-mail send subject="$SystemID GSM Modem SMS Received" to=$EmailAddress body="$smsContent";
expected end of command (line 1 column 28)
[admin@MikroTik] >
[admin@MikroTik] > # Now remove the SMS from the inbox #
[admin@MikroTik] > /tool sms inbox remove $i;
syntax error (line 1 column 25)
[admin@MikroTik] >
[admin@MikroTik] > delay 10;
[admin@MikroTik] >
[admin@MikroTik] > }
[admin@MikroTik] >
[admin@MikroTik] > # clear Receive Enabled, so info channel can be used by other scripts #
[admin@MikroTik] >
[admin@MikroTik] > :log info "SMS to Email script complete";
[admin@MikroTik] >


how i can resolve that??


sorry for my english but i'm not english :(
 
Base122
just joined
Posts: 10
Joined: Tue Mar 13, 2012 4:28 pm

Re: Script on RB411U to check credit on 3G connection

Mon Apr 23, 2012 3:38 pm

Have you checked the Tool/SMS Settings?
SMS Tool Settings.JPG
Do you find an SMS message in the INBOX??
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: No registered users and 26 guests