Back again…
I can’t share our field-implemented code, so I’ve spent way more time than my manager would be happy with adapting it to just configure an RS232 PPP connection between a TRB256 and a CR310 (although this should work fine on just about all Campbells loggers). Seems to be reasonably robust and I imagine there are still some bugs in there, but I’m hoping this will help anyone needing to make a similar connection.
One thing that did cross my mind in all of this: I was assuming that this strange need to send an ATE1 command to the modem was a Teltonika requirement, but it could equally be something that the datalogger needs to kick-start PPP… If anyone (looking at you, @rkivl and @Daumantas ) is able to shed some light on this that would be great.
babbey
' small script to test resetting a TRB256 modem and re-establishing the PPP connection
Public _ As String * 1 : ReadOnly _ :
Public Program_Status As String * 100
Public Modem_Status As String * 100
Public __ As String * 1 : ReadOnly __ :
Public PTemp, Batt_volt
Public RSSI_Value As String
Public IP_Addr As String * 20
Public ___ As String * 1 : ReadOnly ___ :
Public Modem_Reset As Boolean
'Define Subroutines
Sub Delay_With_Message(Delay_Ctr As Long, CountDown_Message As String * 100, Completed_Message As String * 50)
Do While Delay_Ctr > 0
Delay_Ctr -= 1
Sprintf(Modem_Status,CountDown_Message & " (%i secs)",Delay_Ctr)
Delay(1,1,sec)
Loop
Modem_Status = Completed_Message
EndSub 'Delay_With_Message
'Main Program
BeginProg
Program_Status = "BeginProg"
Modem_Reset = 0
IP_Addr = IPInfo(1,0)
Scan (2,Sec,0,0)
Battery(Batt_volt)
PanelTemp(PTemp,_50Hz)
If IP_Addr <> "0.0.0.0" Then Sprintf(Modem_Status,"IP Address = %s",IP_Addr)
NextScan
SlowSequence
Scan (1,Sec,0,0)
If IP_Addr = "0.0.0.0" Then
Modem_Status = "IP Address Unavailable"
Modem_Reset = 1
Delay_With_Message(35,"IP Address Unavailable, resetting modem in","Modem reset begun") ' Need this delayed message to know what's happening after sending program to logger
EndIf
If Modem_Reset <> 0
Program_Status = "Modem Reset routine"
Dim Modem_Query1 As String * 50
Dim CSQ_Result(2) As Long, RSSI_result
Dim RSSI_Str As String * 30
Dim Ok1 As Boolean
Dim Retry1 As Long
Dim Echo_Query As String * 50
Dim Echo_Ok As Boolean
Dim Echo_Retry As Long
#If (LoggerType = CR1000X) OR (LoggerType = CR350)
SW12(SW12_1,1) 'When MODEM_HARDWARE_RESET is enabled using a CR1000X logger, SW12-1 is dedicated to switching Modem Reset Relay.
#Else
SW12(1)
#EndIf
Delay(1,1,Sec)
Modem_Status = "Modem Powered Down"
IP_Addr = "0.0.0.0"
Delay_With_Message(40,"Modem powering up in","Modem powered up")
#If (LoggerType = CR1000X) OR (LoggerType = CR350)
SW12(SW12_1,0)
#Else
SW12(0)
#EndIf
Modem_Status = "Modem Powering Up..."
Program_Status = "Modem Powerup Cycle"
Delay_With_Message(90,"Modem powerup completing in","Poerup Cycle complete")
Modem_Status = "Modem powercycled, attempting to establish PPP connection..."
RSSI_result = NAN
RSSI_Str = "Unavailable"
SerialOpen (ComRS232,115200,3,0,300)
SerialFlush(ComRS232)
For Retry1 = 1 To 3
Program_Status = "Sending AT+CSQ"
Delay(1,500,mSec)
SerialOut(ComRS232,"AT+CSQ" + CHR(13),"",1,20)
SerialIn(Modem_Query1,ComRS232,100,0,50)
SplitStr(CSQ_Result,Modem_Query1,"",2,0)
Ok1 = InStr(1,Modem_Query1,"+CSQ:",2) > 0 AND ((CSQ_Result(1) >=0) AND (CSQ_Result(1) < 100))
If (CSQ_Result(1) >=0) AND (CSQ_Result(1) <=30) Then ExitFor
Next Retry1
If Ok1 Then
If (CSQ_Result(1) >=0) AND (CSQ_Result(1) <=31) Then
RSSI_result = CSQ_Result(1) * 2 - 113
RSSI_Str = Round(RSSI_result,0)
EndIf
Else
Modem_Status = "Signal strength query failed"
EndIf
SerialClose(ComRS232)
RSSI_Value = RSSI_result
SerialOpen (ComRS232,115200,3,0,1000)
SerialFlush(ComRS232)
For Echo_Retry = 1 To 3
Program_Status = "Sending ATE1"
Delay(1,500,mSec)
SerialOut(ComRS232,"ATE1" + CHR(13),"",1,20)
SerialIn(Echo_Query,ComRS232,100,0,50)
Echo_Ok = InStr(1,Echo_Query,"OK",2)
If Echo_Ok Then ExitFor
Next Echo_Retry
Modem_Reset = 0
SerialClose(ComRS232)
Program_Status = "SerialClose"
EndIf
IP_Addr = PPPOpen
Program_Status = "PPP configured! :)"
NextScan
EndProg