Logic Machine Forum
Check the amount of mobile account! - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Check the amount of mobile account! (/showthread.php?tid=424)



Check the amount of mobile account! - phongvucba - 12.10.2016

Has anyone done this before, I need help from you Sad.
I have a prepaid phone sim (In sim have money), inserted in USB3G. And try to use the message through LM3.
One time, I wanted to check in sim phone how much money? Please help me write a script to check this?
I got this idea because I've seen at Alert notification messages to sim phone( pic 1)
I was in Vietnam, I use Viettel sim. Syntax to check the remaining amount is : *101#       or        *102#
Thanks everyone!


RE: Check the amount of mobile account! - Erwin van der Zwart - 12.10.2016

Hi,

I don't think this data is available on the SIM itself.

Normaly you send sms to provider and you reveive the
value back by SMS.

It is possible to receive this reply sms and gsub the data from the received string.

You have to check out what string you need to send to , and what number to use for, your provider to receive the reply.

If you know those 2 items it's easy to create your wish.

BR,

Erwin

Sorry, i see now that you already receive the SMS with the reply.

You can fetch the saldo from the received string by using:

amount = receiveddata:match("stringbeforedatapart(.-)stringafterdatapart")

BR,
Erwin


RE: Check the amount of mobile account! - phongvucba - 13.10.2016

you can specify how to do it?
in SmsHander, I need to add this code somewhere. and what to do next.
I'm new employees, should also have little trouble.
thank you very much!
--------
amount = receiveddata:match("stringbeforedatapart(.-)stringafterdatapart")
--------


RE: Check the amount of mobile account! - Erwin van der Zwart - 13.10.2016

Hi,

It should be something like this inside the SMS handler:

Code:
-- incoming sms handler
handler = function(sms)
 alert('incoming sms: [%s] %s', tostring(sms.sender), tostring(sms.data))
  --******************************************
 -- PUT HERE YOUR MATCH TO GET SMS PREPAID VALUE FROM SMS MESSAGE
 local amount = sms.data:match([[va (.-) SMS]])
 if amount ~= nil then
   amount = tonumber(amount)
   -- do something with amount
 end
 -- END MATCH TO GET SMS PREPAID VALUE FROM SMS MESSAGE
 --******************************************
 -- sms from known number, call parser
 if table.contains(numbers, sms.sender) then
   parser(sms.data, sms.sender)
 end
end

Now i fetch the value from the part of text ''va 550 SMS', now the match function grabs the 550 value out of the string, after that i make it a number instead of a string and you can do whatever you want with it.

BR,

Erwin van der Zwart


RE: Check the amount of mobile account! - phongvucba - 15.10.2016

Thank you much! Erwin van der Zwart
But I still do not get it.
Now I want to dial * 101 # and then click OK. Then the phone will return "Your account was original 1900 VND" ;It notified the form of a pop-up.
Then, we create an object type:
sendsms ('* 101 #', 'amount of value')
Is it right? Sad
Please teach me, how to check the number


RE: Check the amount of mobile account! - Erwin van der Zwart - 15.10.2016

Hi,

The pop-up is simple, just use inside the handler code i posted the
command alert('current sim value is: ' .. amount) 

The other question is harder, as you want to dail a number to request
the reply SMS. i never tried that before, maybe admin has script for that.

I would check if you can send SMS to request the value reply, if your provider support that
then you can use current sms script to send the request.

BR,

Erwin


RE: Check the amount of mobile account! - phongvucba - 16.10.2016

Yes ! as I want to dail a number ( ext *101#) to request
the reply SMS. My provider support that ! Smile
Please help me !
Thank so much Erwin , and every one!


RE: Check the amount of mobile account! - Erwin van der Zwart - 16.10.2016

Hi,

Dail a number can be done by the command ATD*101#

Currently the script is build for SMS and the script uses now the command
AT+CMGS

You need to change the script by using the ATD command. 
If you lookup documentation for AT commands for GSM modem you 
can get all needed info.

I see no usecase for this and are not going to build this myself, so i won't spend
my time on re-writing the sms handler to a dailer.

See: https://www.sparkfun.com/datasheets/Cellular%20Modules/AT_Commands_Reference_Guide_r0.pdf

With this info you have the direction to go for (:

Good luck!


RE: Check the amount of mobile account! - phongvucba - 06.08.2017

Please help me! I have some problems.
I see ! When a message arrives (as shown below)
I want to retrieve the message sequence, what should I do?
The purpose is to take that string, to control something (control the lights by SMS).
Can someone help me?

Thank all!