I use a GoIP GSM to ethernet Sip adapter as part of my freeswitch voip installation which runs alongside Donotiga on my OpenRD arm server.
The GoIP adapter has an SMS sending capability which I want to use in Domotiga, I have been experimenting to see how this is done and I can now send an SMS.
To do this I have modified the CSMS class to replace the modem commands with UDP messages, not a very elegant solution at present but it is now working.
The SMS setup dialog is now used for the GoIP settings
Serial Port = GoIP network address
Pin Code = GoIP SMS password
Service Centre = GoIP UDP port No
Send to GSM #, phone No as before
Baud Rate, unused
I need to add some error checking etc, but the reason for posting is to ask how should I integrate this into the Domotiga system, perhaps still allowing serial modem communications as an option. Should there be an alternative SMS class? should the two methods be combined into one? Any ideas gratefully recieved. Here is the code of the modified CSMS. class file
Code: Select all
' Gambas class file
' Description:
' CSMS.class
' Support for SMS modem for outgoing SMS text messages
' Development Status:
' Heavily modified for GoIP GSM network adapter
' DomotiGa - an open source home automation program.
' Copyright(C) 2008-2009 Ron Klinkien
' Read file called COPYING for license details.
PROPERTY Port AS String
PROPERTY Baud AS String
PROPERTY PIN AS String
PROPERTY ServiceCentre AS String
PROPERTY Contact AS String
PROPERTY SMSDebug AS Boolean
PRIVATE sPort AS String
PRIVATE sBaud AS String
PRIVATE sPIN AS String
PRIVATE sServiceCentre AS String
PRIVATE sContact AS String
PRIVATE bSMSDebug AS Boolean
'PRIVATE sUDPHost AS String
'PRIVATE sUDPPort AS String
PUBLIC hSMS AS NEW UdpSocket
PRIVATE sManufacturer AS String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' open serial port
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC FUNCTION Connect() AS Boolean
' try to close the port
TRY hSMS.Close
' get a new one
hSMS = NEW UdpSocket AS "SMS"
hSMS.Bind(0)
' all ok
RETURN TRUE
CATCH ' some errors
Main.WriteLog(("SMS Error: ") & ERROR.Text)
RETURN FALSE
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' disconnect from the host
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC FUNCTION Disconnect() AS Boolean
' try to close the connection
TRY hSMS.Close
Main.WriteLog(("SMS UDP socket unbind."))
' all ok
RETURN TRUE
CATCH ' some errors
Main.WriteLog(("SMS Error: ") & ERROR.Text)
RETURN FALSE
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' send data via UDP
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB SendUDPPacket(bBuf AS String)
' sent it to configured interface
hSMS.TargetPort = "9991" 'sUDPPort
hSMS.TargetHost = "192.168.2.130" 'sUDPHost
'bBuf.Length = bBuf.Length
'hSMS = hSMS
WRITE #hSMS, bBuf, Len(bBuf)
' bBuf.Write(hSMS, 0, bBuf.Length)
' bBuf.Write(hSMS, 0, 5)
IF bSMSDebug THEN Main.WriteDebugLog(("[SMS] ") & bBuf)
CATCH
Main.WriteLog(("ERROR: Cannot send UDP message! ") & ERROR.Text & (" at ") & ERROR.Where)
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' display error if connect failed
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB SMS_Error()
' handle error
SELECT CASE hSMS.Status
CASE Net.CannotCreateSocket
Main.WriteLog(("SMS: The system does not allow to create a socket."))
CASE Net.CannotBindSocket
Main.WriteLog(("SMS: Unable to bind a socket."))
CASE Net.CannotRead
Main.WriteLog(("SMS: Error reading data."))
CASE Net.CannotWrite
Main.WriteLog(("SMS: Error writing data."))
END SELECT
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' initialize SMS modem, enter PIN if needed
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB InitModem() AS Boolean
RETURN TRUE
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' set or get SMS service center
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRIVATE SUB SetServiceCenter() AS Boolean
RETURN FALSE
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' create SMS message and send it to modem
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB SendSMS(sText AS String, sTo AS String) AS Boolean
DIM sTemp, sData, sResult AS String
DIM iTries AS Integer = 32
DIM sBuf AS String
hSMS.TargetHost = sPort ' "192.168.2.130"
hSMS.TargetPort = sServiceCentre '"9991"
sBuf = "MSG 1234 5678 " & sText
WRITE #hSMS, sBuf, Len(sBuf)
Main.WriteLog(("> ") & sBuf & "\n")
READ #hSMS, sData, Lof(hSMS)
Main.WriteLog(("< ") & sData & "\n")
sBuf = Replace(sData, "\n", "") & " " & sPIN
WRITE #hSMS, sBuf, Len(sBuf)
Main.WriteLog(("> ") & sBuf & "\n")
READ #hSMS, sData, Lof(hSMS)
Main.WriteLog(("< ") & sData & "\n")
sBuf = Replace(sData, "\n", "") & " 5678 " & sTo
WRITE #hSMS, sBuf, Len(sBuf)
Main.WriteLog(("> ") & sBuf & "\n")
READ #hSMS, sData, Lof(hSMS)
Main.WriteLog(("< ") & sData & "\n")
READ #hSMS, sData, Lof(hSMS)
Main.WriteLog(("< ") & sData & "\n")
sBuf = "DONE 1234"
WRITE #hSMS, sBuf, Len(sBuf)
Main.WriteLog(("> ") & sBuf & "\n")
READ #hSMS, sData, Lof(hSMS)
Main.WriteLog(("< ") & sData & "\n")
RETURN TRUE
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' read SMS messages
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB ReadSMS() AS String
DIM sResult AS String
IF bSMSDebug THEN Main.WriteDebugLog(("[SMS] ReadSMS:"))
RETURN sResult
END
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' implement the properties
PRIVATE FUNCTION Port_Read() AS String
RETURN sPort
END
PRIVATE SUB Port_Write(sValue AS String)
sPort = sValue
END
PRIVATE FUNCTION Baud_Read() AS String
RETURN sBaud
END
PRIVATE SUB Baud_Write(sValue AS String)
sBaud = sValue
END
PRIVATE FUNCTION PIN_Read() AS String
RETURN sPIN
END
PRIVATE SUB PIN_Write(sValue AS String)
sPIN = sValue
END
PRIVATE FUNCTION Contact_Read() AS String
RETURN sContact
END
PRIVATE SUB Contact_Write(sValue AS String)
sContact = sValue
END
PRIVATE FUNCTION ServiceCentre_Read() AS String
RETURN sServiceCentre
END
PRIVATE SUB ServiceCentre_Write(sValue AS String)
sServiceCentre = sValue
END
PRIVATE FUNCTION SMSDebug_Read() AS Boolean
RETURN bSMSDebug
END
PRIVATE SUB SMSDebug_Write(sValue AS Boolean)
bSMSDebug = sValue
END
Best regards, David.