de Nathanael Wright | Atualizada: 02/07/2019 | Comentários: 5
In this blog article, we’ll look at how to monitor your data usage using serial commands with our external CELL2XX series of cellular modules using the CR800, CR850, CR1000, and CR3000 dataloggers. (If you have a CR300, CR310, CR6, or CR1000X datalogger, you'll want to read the first blog article in this series.)
The CR800, CR850, CR1000, and CR3000 dataloggers can retrieve cellular data usage information from the external CELL2XX series of Campbell Scientific cellular modules. You can use this data in your data logger programs to turn off interfaces and perform a variety of functions.
To start monitoring your data usage, follow the five-step process outlined below.
To start monitoring your data usage with CRBasic code, first declare your variable(s) and assign units to the variable(s). In my example below, I am using “modem_current_day_usage,” “modem_current_month_usage,” "modem_previous_day_usage,” and “modem_previous_month_usage.”
Public modem_current_day_usage As Long 'Today data usage statistics Public modem_current_month_usage As Long 'Current month's data usage Public modem_previous_day_usage As Long 'Previous day's data usage Public modem_previous_month_usage As Long 'Previous month's data usage Units modem_current_day_usage = kB Units modem_previous_day_usage = kB Units modem_current_month_usage = kB Units modem_previous_month_usage = kB
If you want to store the usage information in a DataTable, create a new DataTable or add the values to an existing DataTable. Options are included for current day's usage, previous day's usage, current month's usage, and previous month’s usage:
DataTable(CELL_DIAGNOSTICS, TRUE, 10) DataInterval (0,15,Sec,10) Sample(1, modem_current_day_usage, IEEE4) Sample(1, modem_previous_day_usage, IEEE4) Sample(1, modem_current_month_usage, IEEE4) Sample(1, modem_previous_month_usage, IEEE4) EndTable
Within your Scan() sequence, ensure that you reset your variables every time so you know you are getting good data. Using your variable(s) you can run their values against conditional statements to program your logger’s behavior.
SlowSequence Scan(2, MIN, 0, 0) modem_current_day_usage = 0 modem_current_month_usage = 0 modem_previous_day_usage = 0 modem_previous_month_usage = 0
To retrieve your values from the modem, follow these steps:
Each group of serial instructions sends a different request to the modem. The examples below use “show usage today” for today’s cellular usage, “show usage yesterday” for yesterday’s cellular usage, “show usage month” for the current month’s cellular usage, and “show usage lastmonth” to show the previous month’s cellular usage.
'Query for today's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage today" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_current_day_usage = returned_value 'Query for yesterday's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage yesterday" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_previous_day_usage = returned_value 'Query for this month's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage month" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_current_month_usage = returned_value 'Query for last month's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage lastmonth" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_previous_month_usage = returned_value
If you are recording your data to a table, ensure you are writing your values using the CallTable() instruction. To avoid interrupting the reading of our other sensors during normal program operation, I placed my CallTable() instruction in a SlowSequence. (This is more relevant if you are using a larger number of commands than what we are using in this example and may not be necessary for your situation.) Be sure to use the CallTable() instruction if you are recording the values.
CallTable CELL_DIAGNOSTICS
When you have completed the steps, your program should look similar to this:
'CR1000 Series Datalogger 'Declare Variables Public modem_current_day_usage As Long 'Today data usage statistics Public modem_current_month_usage As Long 'Current month's data usage Public modem_previous_day_usage As Long 'Previous day's data usage Public modem_previous_month_usage As Long 'Previous month's data usage Public returned_value As String * 70 'Temp string for returned modem values Public PTemp, Batt_volt Const CRLF== CHR(13)+CHR(10) Units modem_current_day_usage = kB Units modem_previous_day_usage = kB Units modem_current_month_usage = kB Units modem_previous_month_usage = kB 'Define Data Tables. DataTable (VoltTemp,1,-1) 'Set table size to # of records, or -1 to autoallocate. DataInterval (0,15,Sec,10) Minimum (1,Batt_volt,FP2,False,False) Sample (1,PTemp,FP2) EndTable DataTable(CELL_DIAGNOSTICS, TRUE, 10) DataInterval (0,10,Min,10) Sample(1, modem_current_day_usage, IEEE4) Sample(1, modem_previous_day_usage, IEEE4) Sample(1, modem_current_month_usage, IEEE4) Sample(1, modem_previous_month_usage, IEEE4) EndTable 'Main Program BeginProg Scan (1,Sec,0,0) PanelTemp (PTemp,60) Battery (Batt_volt) 'Enter other measurement instructions 'Call Output Tables 'Example: CallTable VoltTemp NextScan SlowSequence Scan(2, MIN, 0, 0) modem_current_day_usage = 0 modem_current_month_usage = 0 modem_previous_day_usage = 0 modem_previous_month_usage = 0 SerialOpen (ComSDC11,115200,0,0,50) 'Query for today's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage today" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_current_day_usage = returned_value 'Query for yesterday's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage yesterday" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_previous_day_usage = returned_value 'Query for this month's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage month" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_current_month_usage = returned_value 'Query for last month's cellular data usage SerialFlush(ComSDC11) SerialOut(ComSDC11, "show usage lastmonth" & CRLF, CRLF, 1, 200) SerialIn(returned_value, ComSDC11, 100, CHR(13), 1000) modem_previous_month_usage = returned_value CallTable CELL_DIAGNOSTICS NextScan EndProg
Additional cellular modem values are available that you can use. A short list is below:
modem_apn 'Current Access Point Name modem_battery_voltage 'Modem's current battery voltage modem_current_day_usage 'Today data usage statistics modem_current_month_usage 'Current month's data usage modem_diversity 'Current setting for Diversity Antenna modem_ecio 'Current ECIO value (3G signal quality) modem_ipprotocol 'Current IP Protocol setting (IPv4, IPv6, or IPv4/IPv6) modem_mode 'Current modem mode (PPP or Serial Server) modem_previous_day_usage 'Previous day's data usage modem_previous_month_usage 'Previous month's data usage modem_rsrp 'Current modem RSRP value (LTE signal Strength) modem_rsrq 'Current modem RSRQ value (LTE signal Quality) modem_rssi 'Current modem RSSI value (3G signal strength) modem_sdc_address 'Modem's current SDC address (CS I/O Port SDC Address setting) *Default is SDC11 modem_state 'Current state of the modem (status) modem_is_off modem_reset_needed
You can download the CELL2XX Settings example program that uses these values.
You can monitor and program control functions into your data logger based upon data usage and other values associated with Campbell Scientific's internal and external cellular modems. Options available include: "show usage today," "show usage yesterday," "show usage month," and "show usage lastmonth."
Credits: All my code examples are derived from code created by Gary Roberts, Product Manager over communications and software products at Campbell Scientific, Inc.
I hope you found this program example helpful. Try using the code to monitor your data usage, and post a comment below about your experience. Also, please post any questions you may have.
Comentários
Saadi Al-Musawi | 01/30/2019 at 09:11 PM
I absolutely love the blogs that you post Nathanael, the two parts for integrated and standalone CELL modems. Thank you
Nathanael | 02/01/2019 at 12:21 PM
Thank you! I'm glad you like them.
TonyLeDonne | 02/01/2019 at 01:30 PM
Hi Nathanael,
I am trying to monitor modem statistics for a CR800 and CELL210. The CELL210 is connected to the datalogger in the RS232 Port instead of the CS I/O port, but I have adjusted the COMPort value accordingly. My program will not compile using the blog article instructions, as I do not see what "CRLF" is or where it is declared. I see you are using it as a "waitstring" value, but could you give more explanation to what this is?
Additionally, your "Outstring" value in the SerialOut instruction contains a string & "CRLF". Is this string arbitrary, and only used to describe the field you are retrieving?
Finally, when monitoring modem statistics in a CR300 I have access to modem info and status, as well as modem state. Are these fields also available to pull into a data table for the CR800?
Thank you in advance!
TonyLeDonne | 02/04/2019 at 03:40 PM
Just to answer a few of my own questions from my comment above: CRLF stands for carriage return line feed, which enters a carriage return and begins at the next line.
The Outstring values are not arbitrary, and the specific string you need can be found in the CELL210 manual. The manual lists many commands you can use with the SerialIn and SerialOut instructions.
Nathanael | 02/04/2019 at 07:11 PM
There is a long list of status commands available in section C.1 of the CELL200 manual on pg56:
Examples include: show billing, show phone, show band, show operator, and et cetera.
For modem state information use the two below:
show state
Returns the modem state in English. Values returned could include (but not limited to) "Power off.", "Powering up.", "Powered up.", "SIM authorized.", "Setting baud rate.", "Waiting for baud rate.", "Baud rate set.", "Baud rate failure.", "Power off. Waiting for retry.", "Powered up. SIM auth failure.", "Querying modem.", "Waiting for network registration.", "Configuring modem.", "Dialing.", "Dialing (retry).", "Dialed.", "PPP negotiation.", "Network ready.", "PPP closing.", "PPP paused.", "PPP dropped.", "Terminal AT command mode.", "Firmware update mode.", “Shutting down.”
show state num
Returns the state number associated with show state values.
Does that info answer the rest of your question?
Please log in or register to comment.