We're trying to set up our weather station to send all the data in our FTP server using the program below but we don't have any success on it till now, no single file is received by our sever.
We even try to check if the modem is working fine but when the FXT009 was connected to hyper terminal, it's not responding to AT command even the AT then enter, no OK response at all.
We really don't know how to figure this out, our weather station is using CR1000 logger and FXT009 modem connected to RS232.
It is really frustrating now, please help us out if there's a problem with the program we used (below) or modem problem or any solution that can be made?
'ET107
'Created by Short Cut (2.8)
'Declare Variables and Units
SequentialMode
' -- Constants ------------------------------------------------------------------------
Const INTERNET_APN = "web2" ' The APN to use to connect to the internet
Dim WSStr As String * 21
Dim ByteRet
Dim ChkSumF As Boolean
Dim AirTC_16
Dim AirTC_18
Dim CurrentTime(9)                ' Stores the current datalogger time
Dim TimeStampStr As String        ' A timestamp string for appending to FTP file names
Dim LastFileName_Weather As String * 128  ' Stores the name of the last weather file stored to the user drive
Dim LastFileName_Daily As String * 128    ' Stores the name of the last daily file stored to the user drive
Dim LastRemName As String * 128   ' Stores the name of the last weather file queued to be sent via FTP
Public BattV
Public EncRH
Public Rain_mm
Public AirTC
Public RH
Public SlrkW
Public SlrMJ
Public WSData(3)
Public N(9)
Public PTemp_C
Public TdC
Public SVPWkPa
Public H
Public Ea
Public VPD
Public ModemReset_Now As Boolean    ' Used to reset the GSM modem
Alias WSData(1)=WindDir
Alias WSData(2)=WS_ms
Alias WSData(3)=WSDiag
Alias N(1)=SmplsF
Alias N(2)=Diag1F
Alias N(3)=Diag2F
Alias N(4)=Diag4F
Alias N(5)=Diag8F
Alias N(6)=Diag9F
Alias N(7)=Diag10F
Alias N(8)=NNDF
Alias N(9)=CSEF
Units BattV=Volts
Units EncRH=%
Units Rain_mm=mm
Units AirTC=Deg C
Units RH=%
Units SlrkW=kW/m^2
Units SlrMJ=MJ/m^2
Units PTemp_C=Deg C
Units TdC=Deg C
Units SVPWkPa=kPa
Units WindDir=Degrees
Units WS_ms=meters/second
' -- Get Timestamp --------------------------------------------------------------------
Function GetTimeStamp As String * 30
  ' Declare some temporary variables
  Dim gts_i As Long
  Dim gts_returnstr As String * 30
  Dim gts_rtime(9)
  ' Get the current logger time
  RealTime(gts_rtime())
  ' Create a new timestamp
  gts_returnstr = ""
  For gts_i = 1 To 6
    gts_returnstr = gts_returnstr + "_" + FormatFloat(gts_rtime(gts_i),"%02.00f")
  Next gts_i
  ' Return the timestamp
  Return gts_returnstr
EndFunction
'Define Data Tables
DataTable(Table1,True,-1)
  DataInterval(0,60,Min,10)
  TableFile ("USR:Weather",8,20,7,24,Hr,0,LastFileName_Weather)
  Average(1,AirTC,FP2,False)
  Average(1,H,FP2,False)
  Average(1,TdC,FP2,False)
  Average(1,Ea,FP2,False)
  Average(1,VPD,FP2,False)
  Average(1,SlrkW,FP2,False)
  Totalize(1,SlrMJ,IEEE4,False)
  WindVector (1,WS_ms,WindDir,FP2,False,0,0,2)
  FieldNames("WS_ms_S_WVT,WS_ms_U_WVT,WindDir_DU_WVT,WindDir_SDU_WVT")
  Maximum(1,WS_ms,FP2,False,False)
  ETsz(AirTC,RH,WS_ms,SlrMJ,312.5,24.2,503,3,0,FP2,False)
  FieldNames("ETos,Rso")
  Totalize(1,Rain_mm,FP2,False)
  Average(1,PTemp_C,FP2,False)
  Sample(1,EncRH,FP2)
  Sample(1,BattV,FP2)
EndTable
DataTable(Table2,True,-1)
  DataInterval(0,1440,Min,10)
  TableFile ("USR:Weatherd",8,20,7,24,Hr,0,LastFileName_Daily)
  Minimum(1,BattV,FP2,False,False)
  Maximum(1,EncRH,FP2,False,False)
  Minimum(1,EncRH,FP2,False,False)
  Maximum(1,AirTC,FP2,False,False)
  Minimum(1,AirTC,FP2,False,False)
  Average(1,AirTC,FP2,False)
  Maximum(1,H,FP2,False,False)
  Minimum(1,H,FP2,False,False)
  Average(1,H,FP2,False)
  Maximum(1,TdC,FP2,False,False)
  Minimum(1,TdC,FP2,False,False)
  Average(1,TdC,FP2,False)
  Maximum(1,Ea,FP2,False,False)
  Minimum(1,Ea,FP2,False,False)
  Average(1,Ea,FP2,False)
  Average(1,VPD,FP2,False)
  Average(1,SlrkW,FP2,False)
  Totalize(1,SlrMJ,IEEE4,False)
  WindVector (1,WS_ms,WindDir,FP2,False,0,0,2)
  FieldNames("WS_ms_S_WVT,WS_ms_U_WVT,WindDir_DU_WVT,WindDir_SDU_WVT")
  Maximum(1,WS_ms,FP2,False,False)
  Totalize(1,Rain_mm,FP2,False)
EndTable
'Main Program
BeginProg
  ' Make sure a user drive has been set up
  SetStatus("USRDriveSize","512000")
  ' Clear the user drive on startup
  FileManage ("USR:",16 )
  ' Set up the FTP module
  Call FTP_Setup("ftp server","username","password",INTERNET_APN)
' (Server As String * 128,User As String * 128,Pass As String * 128,APN As String * 128)
  SerialOpen(Com1,38400,3,0,145)
  Scan(5,Sec,1,0)
    'Default Datalogger Battery Voltage measurement BattV
    Battery(BattV)
    'Default CS210 measurement EncRH
    VoltSe(EncRH,1,mV2500,10,False,0,_60Hz,0.1,0)
    If EncRH>100 Then EncRH=100
    'TE525 Rain Gauge measurement Rain_mm
    PulseCount(Rain_mm,1,2,2,0,0.254,0)
    'HMP50 Temperature & Relative Humidity Sensor measurements AirTC and RH
    PortSet(9,1)
    Delay(0,200,mSec)
    VoltSe(AirTC,1,mV2500,2,False,0,_60Hz,0.1,-40)
    VoltSe(RH,1,mV2500,1,False,0,_60Hz,0.1,0)
    If (RH>100) AND (RH<108) Then RH=100
    'CS305 Pyranometer measurements SlrMJ and SlrkW
    VoltDiff(SlrkW,1,mV7_5,3,true,0,_60Hz,0.200,0)
    If SlrkW<0 Then SlrkW=0
    SlrMJ=SlrkW*0.005
    'WindSonic1 Two Dimensional Sonic Wind Speed & Direction Sensor measurements WindDir, WS_ms, and WSDiag
    'Get data from WindSonic1
    SerialInRecord(Com1,WSStr,&h02,0,&h0D0A,ByteRet,00)
    WindDir=Mid(WSStr,3,3)
    WS_ms=Mid(WSStr,7,6)
    WSDiag=Mid(WSStr,16,2)
    ChkSumF = HexToDec(Mid(WSStr,20,2)) Eqv CheckSum(WSStr,9,18)
    'Set diagnostic variables as needed
    If ChkSumF AND WSDiag=0 Then SmplsF=1 Else SmplsF=0
    Move(Diag1F,6,0,1)
    Select Case WSDiag
    Case=1
      Diag1F=1
    Case=2
      Diag2F=1
    Case=4
      Diag4F=1
    Case=8
      Diag8F=1
    Case=9
      Diag9F=1
    Case=10
      Diag10F=1
    EndSelect
    If ByteRet<>21 Then NNDF=1 Else NNDF=0
    If NOT (ByteRet=21 IMP ChkSumF) Then CSEF=1 Else CSEF=0
    'Wiring Panel Temperature measurement PTemp_C
    PanelTemp(PTemp_C,_60Hz)
    'Dew Point calculation TdC
    AirTC_16=AirTC
    DewPoint(TdC,AirTC_16,RH)
    If TdC>AirTC_16 OR TdC=NAN Then TdC=AirTC_16
    'Saturation vapor pressure calculation SVPWkPa
    AirTC_18=AirTC
    SatVP(SVPWkPa,AirTC_18)
    'User Entered Calculation
    H = RH
    'User Entered Calculation
    Ea = (RH/100)*SVPWkPa
    'User Entered Calculation
    VPD = SVPWkPa - Ea
    'Call Data Tables and Store Data
    CallTable(Table1)
    CallTable(Table2)
    ' -- Trigger FTP --
    ' If it is time to send the weather table
    If LastFileName_Weather <> "" Then
      ' Create a remote file name
      LastRemName = "weather/CR1000" + GetTimeStamp() + ".csv"
      ' Queue the file to be sent via ftp
      Call FTP_QueueFile(LastFileName_Weather,LastRemName)
      ' Clear the last file name
      LastFileName_Weather = ""
    EndIf
    ' If it is time to send the daily table
    If LastFileName_Daily <> "" Then
      ' Create a remote file name
      LastRemName = "weather/CR1000_Daily_" + GetTimeStamp() + ".csv"
      ' Queue the file to be sent via ftp
      Call FTP_QueueFile(LastFileName_Daily,LastRemName)
      ' Clear the last file name
      LastFileName_Daily = ""
    EndIf
    ' -- Reset Modem --
    ' Reset the modem every day at 00:30
    If TimeIntoInterval(30,1440,Min) Then ModemReset_Now = TRUE
  NextScan
  ' ===================================================================================
  ' === SLOW SEQUENCE 1 ===============================================================
  ' ===================================================================================
SlowSequence
' === DECLARATIONS ==================================================================
  ' -- Constants ----------------------------------------------------------------------
  Const PPP_TIMEOUT = 60           ' How long to wait until we have a valid PPP connection [s]
  Const FTP_QUEUE_SIZE = 40        ' The number of files to keep in the queue
  Const FTP_MAX_QTIME = 10080      ' The maximum amount of time to keep a file queued [min]
  Const FTP_RETRY_TIME = 30        ' The amount of time to pause between failed attempts [min]
  Const TIMER_PPP_CONNECT = 1      ' Timer used for timing PPP connections
  Const TIMER_PPP_DISCONNECT = 2   ' Timer used for timing PPP disconnections
' -- Public Variables ---------------------------------------------------------------
  Public PPP_IPAddress As String * 20                             ' The current datalogger IP address
  Public PPP_APN As String * 128                                  ' The access point for PPP connection
  Public FTP_Server As String * 128                               ' The ftp server to connect to
  Public FTP_Username As String * 128                             ' The username for the server
  Public FTP_Password As String * 128                             ' The password for the server
  Public FTP_Queue_Pos As Long                                    ' The position of the last file in the queue
  Public FTP_Queue_LocalFiles(FTP_QUEUE_SIZE) As String * 64      ' List of local files waiting to be sent
  Public FTP_Queue_RemoteFiles(FTP_QUEUE_SIZE) As String * 128    ' The remote file name to use for this file
  Public FTP_Queue_QTime(FTP_QUEUE_SIZE) As Long                  ' The time this file was queued [nsec]
  Public FTP_Queue_AttemptTime(FTP_QUEUE_SIZE) As Long            ' The last time this file failed to be sent [nsec]
  ' -- Local Variables ----------------------------------------------------------------
  Public FTP_ReadyFiles As Long       ' Counts files ready to be sent
  Public FTP_ScanTime As Long         ' Records the nsec time of the current scan
  Dim FTP_Result As Boolean        ' The result of the last ftp send
  Dim PPP_CloseResult As Boolean   ' The result of the last attempt to disconnect PPP
  Public ftp_i As Long                ' Used for iterations
' === SUB ROUTINES===================================================================
  ' -- GSM Modem Reset ----------------------------------------------------------------
  Sub ModemReset_GSM
    ' Open the serial port to the modem
    SerialOpen (COMRS232,115200,3,0,50)
    ' Send the reset command
    SerialOut (COMRS232,CHR(13) + "AT+CFUN=1" + CHR(13),"OK",2,500)
    ' Wait for 10 seconds for the modem to reset
    Delay(0,10,Sec)
    ' Flush the serial port
    SerialFlush (COMRS232)
    ' Close the serial port
    SerialClose(COMRS232)
  EndSub
  ' -- Setup FTP ------------------------------------------------------------------------
  Sub FTP_Setup(Server As String * 128,User As String * 128,Pass As String * 128,APN As String * 128)
    ' Set the FTP settings
    FTP_Server = Server
    FTP_Username = User
    FTP_Password = Pass
    ' Set the PPP access point
    PPP_APN = APN
    ' Set up the comport connection to the cellphone
    Call CFG_SetupComport
  EndSub
  ' -- Set Up Comport -----------------------------------------------------------------
  Sub CFG_SetupComport
    ' Declare some temporary variables
    Const MODEM_PORT = ComRS232
    ' Close the PPP connection
    Call PPP_Disconnect
    ' Configure the PPP settings
    If Status.pppInterface(1,1) <> "1" Then SetStatus ("pppInterface","1")
    If Status.pppDial(1,1) <> "AT+CGACT=1,1;ATDT*99***1#" Then SetStatus ("pppDial","AT+CGACT=1,1;ATDT*99***1#")
    If Status.pppDialResponse(1,1) <> "CONNECT" Then SetStatus ("pppDialResponse","CONNECT")
    If Status.BaudrateRS232(1,1) <> "115200" Then SetStatus("BaudrateRS232","115200")
  EndSub
  ' -- Set Up Modem -------------------------------------------------------------------
  Sub CFG_SetupModem
    ' Configure Modem Baud Rate
    SerialOpen (MODEM_PORT,-115200,0,0,1000)
    SerialOut (MODEM_PORT,"AT+IPR=115200" + CHR(13) + CHR(10),"OK",3,50)
    SerialClose (MODEM_PORT)
    SerialOpen (MODEM_PORT,-9600,0,0,1000)
    SerialOut (MODEM_PORT,"AT+IPR=115200" + CHR(13) + CHR(10),"OK",3,50)
    SerialClose (MODEM_PORT)
    ' Configure PPP APN
    SerialOpen (MODEM_PORT,115200,0,0,1000)
    SerialOut (MODEM_PORT,"AT+CGDCONT=1," + CHR(34) + "IP" + CHR(34) + "," + CHR(34) + PPP_APN + CHR(34) + CHR(13) + CHR(10),"OK",3,100)
    SerialOut (MODEM_PORT,"AT&W" + CHR(13) + CHR(10),"OK",3,100)
    SerialClose (MODEM_PORT)
  EndSub
  ' -- FTP Queue File -------------------------------------------------------------------
  Sub FTP_QueueFile(LocalFileName As String * 64,RemoteFileName As String * 128)
    ' If the queue is full, exit the sub routine
    If FTP_Queue_Pos >= FTP_QUEUE_SIZE Then ExitSub
    ' Add to the queue position
    FTP_Queue_Pos = FTP_Queue_Pos + 1
    ' Add the local file name to the queue
    FTP_Queue_LocalFiles(FTP_Queue_Pos) = LocalFileName
    ' Add the remote file name to the queue
    FTP_Queue_RemoteFiles(FTP_Queue_Pos) = RemoteFileName
    ' Record the queue time (nsec)
    FTP_Queue_QTime(FTP_Queue_Pos) = Status.TimeStamp(1,1)
  EndSub
  ' -- FTP Remove File ------------------------------------------------------------------
  Sub FTP_RemoveFile(index As Long)
    ' Declare some temporary variables
    Dim frf_i As Long
    ' If the specified index does not exist in the queue, exit the sub routine
    If index > FTP_Queue_Pos Then ExitSub
    ' Delete the local file from the datalogger
    FileManage (FTP_Queue_LocalFiles(index),8)
    ' Loop through the previous entries in the queue
    For frf_i = (index + 1) To FTP_Queue_Pos
      ' Move each entry down one spot in the list
      FTP_Queue_LocalFiles(frf_i - 1) = FTP_Queue_LocalFiles(frf_i)
      FTP_Queue_RemoteFiles(frf_i - 1) = FTP_Queue_RemoteFiles(frf_i)
      FTP_Queue_QTime(frf_i - 1) = FTP_Queue_QTime(frf_i)
      FTP_Queue_AttemptTime(frf_i - 1) = FTP_Queue_AttemptTime(frf_i)
    Next frf_i
    ' Clear the last entry in the queue
    FTP_Queue_LocalFiles(FTP_Queue_Pos) = ""
    FTP_Queue_RemoteFiles(FTP_Queue_Pos) = ""
    FTP_Queue_QTime(FTP_Queue_Pos) = 0
    FTP_Queue_AttemptTime(FTP_Queue_Pos) = 0
    ' Decrement the queue position
    FTP_Queue_Pos = FTP_Queue_Pos - 1
  EndSub
  ' -- PPP Connect --------------------------------------------------------------------
  Sub PPP_Connect
    ' Start a timer to time how long it takes to connect via PPP
    Timer (TIMER_PPP_CONNECT,Sec,2)
    ' Keep looping until a valid IP address is returned
    Do While PPP_IPAddress = "0.0.0.0"
      ' See if we have a valid IP address yet
      PPP_IPAddress = PPPOpen()
      ' If we have been trying to connect for longer than the timeout period, exit the
      ' loop
      If Timer(TIMER_PPP_CONNECT,Sec,4) >= PPP_TIMEOUT Then ExitDo
      ' Delay 1 second between attempts
      Delay(1,1,Sec)
    Loop
  EndSub
  ' -- PPP Disconnect -----------------------------------------------------------------
  Sub PPP_Disconnect
    ' Reset the PPP Close Result, this may still be TRUE from the last close attempt
    PPP_CloseResult = FALSE
    ' Start a timer to time out the close attempt
    Timer(TIMER_PPP_DISCONNECT,Sec,2)
    ' Keep looping until the PPP connection is successfully closed
    Do While PPP_CloseResult = FALSE  AND Timer(TIMER_PPP_DISCONNECT,Sec,4) < 10
      ' Try to close the PPP connection
      PPP_CloseResult = PPPClose()
    Loop
    ' Reset the datalogger IP address
    PPP_IPAddress = "0.0.0.0"
  EndSub
' === SEQUENCE START ================================================================
  ' Disconnect the PPP link on logger start
  Call PPP_Disconnect
  ' Reset the modem on startup
  ModemReset_Now = TRUE
  Do
    Scan (10,Sec,0,0)
      ' If it is time to reset the modem
      If ModemReset_Now = TRUE Then
        ' Reset the modem
        Call ModemReset_GSM
        ' Turn off the reset flag
        ModemReset_Now = FALSE
        ' Exit the scan to avoid skipped scans
        ExitScan
      EndIf
      ' If the FTP queue is empty, skip the rest of the scan
      If FTP_Queue_Pos = 0 Then ContinueScan
      ' Get the current scan time
      FTP_ScanTime = Status.TimeStamp(1,1)
      ' Initialise the ready to send counter
      FTP_ReadyFiles = 0
      ' Loop through the FTP queue looking for expired files and counting files ready to send
      For ftp_i = 1 To FTP_Queue_Pos
        ' If this file has expired,
        If (FTP_ScanTime - FTP_Queue_QTime(ftp_i)) > (FTP_MAX_QTIME * 60) Then
          ' Remove it from the queue
          Call FTP_RemoveFile(ftp_i)
          ' Subtract one from the iterator
          ftp_i = ftp_i - 1
          ' If this file is ready to send,
        Else If (FTP_ScanTime - FTP_Queue_AttemptTime(ftp_i)) > (FTP_RETRY_TIME * 60) Then
          ' Add to the counter
          FTP_ReadyFiles = FTP_ReadyFiles + 1
        EndIf
      Next ftp_i
      ' If there are no files to send, skip the rest of the scan
      If FTP_ReadyFiles = 0 Then ContinueScan
      ' Make sure the modem is set up correctly
      Call CFG_SetupModem
      ' Open the PPP Link
      Call PPP_Connect
      ' If the PPP link open failed, exit the scan and try again next time
      If PPP_IPAddress = "" Then ExitScan
      ' Loop through the FTP queue looking for files to send
      For ftp_i = 1 To FTP_Queue_Pos
        ' If it is time to send the file in this slot
        If (FTP_ScanTime - FTP_Queue_AttemptTime(ftp_i)) > (FTP_RETRY_TIME * 60) Then
          ' Attempt to send the file over ftp
          FTP_Result = FTPClient (FTP_Server,FTP_Username,FTP_Password,FTP_Queue_LocalFiles(ftp_i),FTP_Queue_RemoteFiles(ftp_i),0)
          ' If the send was a success
          If FTP_Result = TRUE Then
            ' Remove the file from the queue
            Call FTP_RemoveFile(ftp_i)
            ' If the file failed
          Else
            ' Record the time of this attempt
            FTP_Queue_AttemptTime(ftp_i) = FTP_ScanTime
          EndIf
        EndIf
      Next ftp_i
      ' Disconnect the PPP link
      Call PPP_Disconnect
      ' Exit the scan to avoid skipped scans
      ExitScan
    NextScan
  Loop
EndProg
Hi graywacke,
I think you must ensure that the FXT009 gives appropriate AT command respond when connected to hyperterminal before you look further on your CR1000/CRBasic program. Follow the FXT009 setup steps as described in cs_gsm.pdf manual.
 
One question, in your CRBasic program:
 
' -- Set Up Modem --------------------------------------------------------------
Sub CFG_SetupModem
' Configure Modem Baud Rate
SerialOpen (MODEM_PORT,-115200,0,0,1000)
what do you mean with the negative baud rate?