sending_sms_via_gsm_modem
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sending_sms_via_gsm_modem [2018/11/27 11:07] – created akuzmuk | sending_sms_via_gsm_modem [2018/11/27 11:53] (current) – akuzmuk | ||
---|---|---|---|
Line 19: | Line 19: | ||
sendString(" | sendString(" | ||
sendString(" | sendString(" | ||
- | sendString(" | + | sendString(" |
sendString(newValue); | sendString(newValue); | ||
sendString(string.char(26)); | sendString(string.char(26)); | ||
return true; | return true; | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | Protocol parameters: | ||
+ | |||
+ | *Type: Serial Port | ||
+ | *Address validation: ^(SMS[0-9]+)$ | ||
+ | *Validation error message: Invalid phone number. Valid SMS addresses are SMSxxxxxxxxxx where xxxx is a phone number. | ||
+ | |||
+ | Go to **Setup -> Registers -> Tools -> Custom Protocols** and add this protocol. After that you can create connection using this protocol. Some modems could answer on AT commands with huge delays. You might need specify extremely long timeouts for them in connection settings (3-6 seconds!) in you will see such behavior. | ||
+ | |||
+ | Please note that modern modems usually have multiple UARTs (/ | ||
+ | |||
+ | To send SMS to phone number 1234567890 you need to create a register with address SMS1234567890 with data type String. Once register was created you can send SMS to this phone it by writing text to this register. | ||
+ | |||
+ | When WebHMI will get command to write new text to this register it will send needed AT command to modem and modem will send SMS to phone number specified in register address. | ||
+ | |||
+ | |||
+ | If you will have troubles with sending SMS you can use this debug version of custom protocol. It will echo commands and modem replies into WebHMI communication log. This might help you debug the issue. | ||
+ | |||
+ | <code lua> | ||
+ | function createDevices () | ||
+ | addDevice({name = " | ||
+ | end | ||
+ | |||
+ | function readRegister (reg, device, unitId) | ||
+ | return " | ||
+ | end | ||
+ | |||
+ | function writeRegister (reg, device, unitId, newValue) | ||
+ | local replyTmp = "" | ||
+ | | ||
+ | DEBUG(" | ||
+ | --sendString(" | ||
+ | |||
+ | sendString(" | ||
+ | |||
+ | -- Get modem' | ||
+ | replyTmp | ||
+ | if (replyTmp ~= "" | ||
+ | DEBUG(" | ||
+ | end | ||
+ | |||
+ | -- Get text mode parameters | ||
+ | sendString(" | ||
+ | |||
+ | -- Get modem' | ||
+ | replyTmp | ||
+ | if (replyTmp ~= "" | ||
+ | DEBUG(" | ||
+ | end | ||
+ | |||
+ | -- Tell phone number to modem. We are using raw register address and cut phone number from it starting at char #4 | ||
+ | sendString(" | ||
+ | |||
+ | -- Get modem' | ||
+ | replyTmp | ||
+ | if (replyTmp ~= "" | ||
+ | | ||
+ | end | ||
+ | |||
+ | -- Send message (newValue) and line end character (ASCII code #26) | ||
+ | sendString(newValue..string.char(26)) | ||
+ | |||
+ | -- Get modem' | ||
+ | replyTmp | ||
+ | if (replyTmp ~= "" | ||
+ | DEBUG(" | ||
+ | end | ||
+ | |||
+ | return true; | ||
+ | end | ||
+ | |||
+ | function ReadModemReply() | ||
+ | local CR = " | ||
+ | local one_char_tmp = "" | ||
+ | local readStringTmp = "" | ||
+ | | ||
+ | | ||
+ | if (one_char_tmp ~= false) then | ||
+ | readStringTmp = readStringTmp..one_char_tmp | ||
+ | else | ||
+ | DEBUG(" | ||
+ | return "" | ||
+ | | ||
+ | until (one_char_tmp == CR) | ||
+ | readString(1) | ||
+ | | ||
+ | return readStringTmp | ||
+ | |||
end | end | ||
</ | </ |
sending_sms_via_gsm_modem.txt · Last modified: 2018/11/27 11:53 by akuzmuk