This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Help me! Notification SMS from LM using Twilio service
#1
in the code:
  1. value = event.getvalue()

  2.  

  3. from_nr = '+37112345679' -- put sender SIM nr here

  4. to_nr = '+37112345678' -- put recepient SIM nr here

  5. id_nr = 'ACe56f5' -- put your ID here

  6. token_nr = '598c6ff' -- put your token here

  7.  

  8. sms(id_nr, token_nr, from_nr, to_nr, 'The value for 1/1/2 has changed to'..tostring(value))
id_nr and token_nr, Where I see my account?
thank everyone. !  Heart Heart Heart
Reply
#2
Have a look here:
https://www.twilio.com/help/faq/twilio-b...-change-it

id_nr is your Account SID and token_nr is your Auth Token
Reply
#3
(02.03.2016, 12:29)admin Wrote: Have a look here:
https://www.twilio.com/help/faq/twilio-b...-change-it

id_nr is your Account SID and token_nr is your Auth Token

thank admin so much!
"from_nr" and "to_nr" , what it?
thank all!  Confused Confused
Reply
#4
from_nr is Twilio number that is sending the message, in your Twilio account click "Get your first Twilio Number"

to_nr is the phone number that should receive the message
Reply
#5
Hi,
I try to sent SMS by Twilio in VietNam as link:
https://openrb.com/notification-sms-from...desyntax_2

But, it's not working. I used this code for event:

from_nr = '+19177461563' -- Twilio phone number
to_nr = '+84932414151' -- My phone number
id_nr = '...' -- ACCOUNT SID
token_nr = '...' -- AUTH TOKEN

sms(id_nr, token_nr, to_nr, from_nr, 'Test SMS by SL'..tostring(value))
Reply
#6
You have swapped from/to fields. It should be:
Code:
sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))
Reply
#7
(11.10.2019, 06:52)admin Wrote: You have swapped from/to fields. It should be:
Code:
sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))

Same trouble Sad

My Common Funtions:
Code:
--SMS by Twilio
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))

  return request(url, body)
end
My Event:
Code:
value = event.getvalue()

from_nr = '+19177461563' -- put sender SIM nr here
to_nr = '+84938354162' -- put recepient SIM nr here
id_nr = '...' -- put your ID here
token_nr = '...' -- put your token here

sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))
Reply
#8
Replace sms function with this one:
Code:
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))
  local resp = {}
  local stat, code, hdrs = request({
    method = 'POST',
    url = url,
    protocol = 'tlsv12',
    sink = ltn12.sink.table(resp),
    source = ltn12.source.string(body),
    headers = {
      ['content-length'] = #body,
      ['content-type'] = 'application/x-www-form-urlencoded'
    }
  })

  if stat then
    stat = table.concat(resp)
  end

  return stat, code, hdrs
end
Reply
#9
(15.10.2019, 13:53)admin Wrote: Replace sms function with this one:
Code:
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))
  local resp = {}
  local stat, code, hdrs = request({
    method = 'POST',
    url = url,
    protocol = 'tlsv12',
    sink = ltn12.sink.table(resp),
    source = ltn12.source.string(body),
    headers = {
      ['content-length'] = #body,
      ['content-type'] = 'application/x-www-form-urlencoded'
    }
  })

  if stat then
    stat = table.concat(resp)
  end

  return stat, code, hdrs
end

It's working!! Thank you so much Smile

But it takes about 15 min for 1 SMS, too long
Reply
#10
You can try contacting Twilio support or ask your local operators if they provide SMS gateway service.
Reply
#11
(16.10.2019, 10:38)admin Wrote: You can try contacting Twilio support or ask your local operators if they provide SMS gateway service.

Hi, I tried to send command with https with this code:
Code:
local http = require('ssl.https')
mime = require("mime")
res, err = ssl.https.request('https://api.speedsms.vn/index.php/sms/send?access-token=...&to=84938354162&content=hello')
log(res, err)

Log message:
Code:
* arg: 1
  * nil
* arg: 2
  * string: Try again


I can send this link from web browser. But, not working with LM5. Please check and tell me how to fix this?
Thanks
Reply
#12
Try updating LuaSocket library (System config > System > Packages > Add (+) green button)
New CPU: http://dl.openrb.com/pkg/luasocket_2.0.2...9_imx6.ipk
Old CPU: http://dl.openrb.com/pkg/luasocket_2.0.2...09_mxs.ipk
Reply
#13
(18.10.2019, 12:36)admin Wrote: Try updating LuaSocket library (System config > System > Packages > Add (+) green button)
New CPU: http://dl.openrb.com/pkg/luasocket_2.0.2...9_imx6.ipk
Old CPU: http://dl.openrb.com/pkg/luasocket_2.0.2...09_mxs.ipk

Hi,

It's work on LM5. How's about the HL&SL? I don't see update packages function in System page
Reply
#14
Install latest firmware
Reply
#15
(21.10.2019, 09:21)admin Wrote: Install latest firmware

Hi,
I upgraded to ver 2.4.0. Still same trouble Sad
Reply
#16
Hi,
How can I fix this trouble?? W4K and LM5 can work, SL can not Sad

Thanks
Reply
#17
SL is using all the same libraries as W4K as long you use the same version of FW. If it doesn't work your problem is elsewhere.
Reply
#18
Check that your device has correct gateway and DNS set in System config > Network > Interfaces
Reply


Forum Jump: