Changes

3,446 bytes added ,  08:21, 23 August 2023
no edit summary
Line 11: Line 11:     
For the instruction on how to setup 1-Wire sensor with the TRB141 kindly navigate to this [[TRB141 1-Wire Setup/Configuration|article]] that we have.
 
For the instruction on how to setup 1-Wire sensor with the TRB141 kindly navigate to this [[TRB141 1-Wire Setup/Configuration|article]] that we have.
 +
 +
====Disclaimer====
 +
----
 +
1) This configuration together with the custom script is tested and written on the firmware version [https://wiki.teltonika-networks.com/images/1/1c/TRB1_R_00.07.04.2_WEBUI.bin TRB1_R_00.07.04.2] of TRB141. <br>
 +
2) The provided script is written for example purposes only as our devices, specifically TRB141, doesn't have a built-in functionality to send 1-wire data to a specific server.
 +
    
=== Writing the Script ===
 
=== Writing the Script ===
 +
----
 
Connect to the TRB141 CLI via SSH or WebUI.
 
Connect to the TRB141 CLI via SSH or WebUI.
   Line 19: Line 26:  
Navigate to it, then create a new sh file using the “vi” command followed by the filename of your choice. (Don’t forget to add the .sh extension at the end).
 
Navigate to it, then create a new sh file using the “vi” command followed by the filename of your choice. (Don’t forget to add the .sh extension at the end).
   −
<code>vi 1wire_script.sh</code>
+
<pre>vi 1wire_script.sh</pre>
      Line 26: Line 33:  
Copy the provided code and paste it into your script file.
 
Copy the provided code and paste it into your script file.
   −
<code>#!/bin/sh</code>
+
<pre>#!/bin/sh
 
  −
<code># Capture output of ubus call ioman.gpio.onewire status command</code>
  −
 
  −
<code>status=$(ubus call ioman.gpio.onewire status)</code>
  −
 
  −
<code># Parse value of "value" parameters</code>
     −
<code>value=$(echo "$status" | grep -o '"value":[^,}]*' | sed 's/.*: *"\?\([^,"}]*\)"\?/\1/')</code>
+
# Capture output of ubus call ioman.gpio.onewire status command
   −
<code>if [ "$value" -eq 0 ]; then</code>
+
status=$(ubus call ioman.gpio.onewire status)
   −
<code>  ubus call ioman.gpio.onewire update '{"value":"1"}'</code>
+
# Parse value of "value" parameters
 +
value=$(echo "$status" | grep -o '"value":[^,}]*' | sed 's/.*: *"\?\([^,"}]*\)"\?/\1/')
   −
<code>fi</code>
+
if [ "$value" -eq 0 ]; then
   −
<code>BASE_DIR="/sys/bus/w1/devices/"</code>
+
  ubus call ioman.gpio.onewire update '{"value":"1"}'
   −
<code>do</code>
+
fi
   −
<code># Iterate through each sensor directory</code>
+
BASE_DIR="/sys/bus/w1/devices/"
   −
<code>for sensor_dir in $BASE_DIR/28-*; do</code>
+
do
 +
# Iterate through each sensor directory
 +
for sensor_dir in $BASE_DIR/28-*; do
   −
<code>  sensor_id=$(basename $sensor_dir)</code>
+
  sensor_id=$(basename $sensor_dir)
   −
<code>  # Read temperature data from device file and filter it to display up to 2 decimal points</code>
+
  # Read temperature data from device file and filter it to display up to 2 decimal points
   −
<code>  temp_raw=$(cat $sensor_dir/w1_slave | grep "t=" | awk -F"=" '{print $2}')</code>
+
  temp_raw=$(cat $sensor_dir/w1_slave | grep "t=" | awk -F"=" '{print $2}')
   −
<code>  temp=$(echo "$temp_raw" | awk '{printf "%.2f", $1/1000}')</code>
+
  temp=$(echo "$temp_raw" | awk '{printf "%.2f", $1/1000}')
   −
<code>  # Define HTTP server URL and payload data</code>
+
  # Define HTTP server URL and payload data
   −
<code>  SERVER_URL="192.168.2.227"</code>
+
  SERVER_URL="192.168.2.227"
   −
<code>  PAYLOAD="{\"SensorID\": \"$sensor_id\", \"temperature\": $temp}"</code>
+
  PAYLOAD="{\"SensorID\": \"$sensor_id\", \"temperature\": $temp}"
   −
<code>  # Send temperature data to server using cURL</code>
+
  # Send temperature data to server using cURL
   −
<code>  curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" $SERVER_URL</code>
+
  curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" $SERVER_URL
   −
<code>done</code>
+
done</pre>
    
''To use this script, replace the ‘DEVICE_FILE’, ‘SERVER_URL’, and ‘PAYLOAD’ variables with the appropriate values for your system and HTTP server.''
 
''To use this script, replace the ‘DEVICE_FILE’, ‘SERVER_URL’, and ‘PAYLOAD’ variables with the appropriate values for your system and HTTP server.''
Line 86: Line 90:  
After that, it checks if the value stored in the '''‘value’''' variable is equal to 0. If it is, the '''‘ubus’''' command is used to call the '''‘ioman.gpio.onewire’''' service and execute the ‘update’ command, which updates the ‘value’ parameter to 1.
 
After that, it checks if the value stored in the '''‘value’''' variable is equal to 0. If it is, the '''‘ubus’''' command is used to call the '''‘ioman.gpio.onewire’''' service and execute the ‘update’ command, which updates the ‘value’ parameter to 1.
 
[[File:Networking trb user scripts cli code explanation2.png|border|class=tlt-border]]
 
[[File:Networking trb user scripts cli code explanation2.png|border|class=tlt-border]]
      
This line sets the ‘BASE_DIR’ variable to the base directory for 1-wire devices.
 
This line sets the ‘BASE_DIR’ variable to the base directory for 1-wire devices.
    
[[File:Networking trb user scripts cli code explanation3.png|border|class=tlt-border]]
 
[[File:Networking trb user scripts cli code explanation3.png|border|class=tlt-border]]
      
This line sets up a ‘for’ loop to iterate through all directories in ‘$BASE_DIR’ that start with ’28-‘, which is the prefix for 1-wire temperature sensors.
 
This line sets up a ‘for’ loop to iterate through all directories in ‘$BASE_DIR’ that start with ’28-‘, which is the prefix for 1-wire temperature sensors.
Line 98: Line 100:     
[[File:Networking trb user scripts cli code explanation4.png|border|class=tlt-border]]
 
[[File:Networking trb user scripts cli code explanation4.png|border|class=tlt-border]]
      
This block reads the temperature data from the device file '''‘$sensor_dir/w1_slave’''' and extracts the raw temperature value using '''‘grep’''' and '''‘awk’'''. The temperature value is encoded as an integer.
 
This block reads the temperature data from the device file '''‘$sensor_dir/w1_slave’''' and extracts the raw temperature value using '''‘grep’''' and '''‘awk’'''. The temperature value is encoded as an integer.
Line 104: Line 105:  
Which then converts the raw temperature value to degrees Celsius by dividing it by 1000 and then formatting it with two decimal places using '''‘printf’'''. The resulting temperature value is stored in the '''‘temp’''' variable.
 
Which then converts the raw temperature value to degrees Celsius by dividing it by 1000 and then formatting it with two decimal places using '''‘printf’'''. The resulting temperature value is stored in the '''‘temp’''' variable.
   −
[[File:Networking trb user scripts cli code explanation5.png|left|border|class=tlt-border]]
+
[[File:Networking trb user scripts cli code explanation5.png|border|class=tlt-border]]
    +
These lines define the URL of the server to which the temperature data will be sent and the payload data that will be sent with each request. The payload includes the '''‘sensor_id’''' and '''‘temp’''' variables, formatted as a JSON object.
    +
[[File:Networking trb user scripts cli code explanation6.png|border|class=tlt-border]]
    +
This line uses the '''‘curl’''' command to send an HTTP POST request to the server specified by '''‘$SERVER_URL’'''. The '''‘-X POST’''' option specifies that the request should be a POST request, and the '''‘-H “Content-Type: application/json”’''' option specifies that the payload data is in JSON format. The '''‘-d “$PAYLOAD”’''' option specifies the payload data to be sent with the request.
    +
[[File:Networking trb user scripts cli code explanation7.png|border|class=tlt-border]]
    +
=== Output ===
 +
----
 +
[[File:Networking trb user scripts HTTP listener screenshot.png|800x800px|border|class=tlt-border]]]
   −
These lines define the URL of the server to which the temperature data will be sent and the payload data that will be sent with each request. The payload includes the '''‘sensor_id’''' and '''‘temp’''' variables, formatted as a JSON object.
+
Run the script by entering the file path of the file or '''./<filename>.sh''' if you are in the same directory.
   −
[[File:Networking trb user scripts cli code explanation6.png|left]]
+
If configured correctly, you should be able to see the temperature data on your HTTP server.
       +
==Example 2: Mobile Parameters to HTTP Server==
    +
Mobile parameters are needed to measure signal features that can be acquired using
 +
'''gsmctl''' commands. However, there is no available command to check/display all of the desired
 +
details.
    +
With that said, a custom script is needed to show them using one command.
 +
This article provides step-by-step instructions on how to write the script, programs that
 +
are required, and how to run it.
   −
This line uses the '''‘curl’''' command to send an HTTP POST request to the server specified by '''‘$SERVER_URL’'''. The '''‘-X POST’''' option specifies that the request should be a POST request, and the '''‘-H “Content-Type: application/json”’''' option specifies that the payload data is in JSON format. The '''‘-d “$PAYLOAD”’''' option specifies the payload data to be sent with the request.
+
If you're having trouble finding any page or some of the parameters described here on your device's WebUI, you should turn on '''"Advanced WebUI"''' mode. You can do that by '''clicking''' the '''"Basic"''' button '''under "Mode"''', which is located at the top-right corner of the WebUI.
 +
[[File:Networking rutx manual webui basic advanced mode v1.gif|border|class=tlt-border]]
   −
[[File:Networking trb user scripts cli code explanation7.png|left]]
+
====Disclaimer====
 +
----
 +
1) This page describes a custom script that is tested on the latest firmware version at that time ([[RUTX14_Firmware_Downloads|RUTXXX_R_00_07_04_2]]).
    +
2) While we strive to keep the information accurate and up-to-date, these are exclusively meant for illustrative purposes only. It's important to clarify that the functionalities being discussed are not inherent features of our routers. Any reliance you place on the information within this document/website/article is strictly at your own discretion.
    +
===Prerequisites===
 +
----
 +
For this particular configuration you will need:
    +
* A Gateway or a Router with GSM (RUTX14 is being used in the example)
 +
* 1 SIM card
 +
* 1 PC
 +
* HTTP Server (Hercules)
    +
===Preparation===
 +
----
 +
* Prepare RUTX14, power up the device, insert the sim card, check that mobile interface is active and working. SIM1, PWR and signal strength indicators should light up.
   −
=== Output ===
+
'''Network -> Interfaces''' should look similar to this:
[[File:Networking trb user scripts HTTP listener screenshot.png|left|800x800px]]
  −
 
      +
[[File:Blur1.png|border|center|1100px|class=tlt-border]]
    +
===Making a Directory and Script===
 +
----
    +
'''1.''' Connect to RUTX14 CLI using PUTTY or WEBUI.
    +
'''2.''' Create a new directory for the custom script with the following command: <code><span class="highlight">mkdir /etc/config/script</span></code> 
    +
[[File:Directory.png|border|center|1000px|class=tlt-border]]
    +
'''3.''' Then create a new .sh file: <code><span class="highlight">touch /etc/config/script/<filename>.sh</span></code>
    +
[[File:Crop1.png|border|center|class=tlt-border]]
    +
'''4.''' To edit the filename, use <code><span class="highlight">vi <filename>.sh</span></code>. Press '''I'''. To save and exit, '''Press Esc''' then ''':x''' or to exit without saving, '''Press Esc''' then ''':q!'''.
    +
[[File:Crop2.png|border|center|class=tlt-border]]
    +
'''5.''' After editing, save then run command <code><span class="highlight">chmod +x <filename></span></code> to make the script executable.
    +
[[File:Chmod3.png|border|center|class=tlt-border]]
    +
===Testing===
 +
----
 +
'''6.''' Run the script: <code><span class="highlight">/etc/config/script/<filename></span></code>  or if you are inside script directory just run <code><span class="highlight">./<filename></span></code>
    +
[[File:Exec.png|border|center|class=tlt-border]]
   −
Run the script by entering the file path of the file or '''./<filename>.sh''' if you are in the same directory.
+
'''7.''' If all configurations are correct, all parameters should be displayed in the HTTP Server
   −
If configured correctly, you should be able to see the temperature data on your HTTP server.
+
[[File:Blur2.png|border|center|class=tlt-border]]
   −
==Example 2: filtering SMS messages==
+
===Script===
[[File:Configuration examples user scripts 1.png]]
+
----
 +
To get a copy of the whole script, please refer to this [https://wiki.teltonika-networks.com/view/File:Script.pdf file].

Navigation menu