Changes

no edit summary
Line 73: Line 73:  
Press the ‘esc’ on your keyboard to exit insert mode, then type :x, and press enter.
 
Press the ‘esc’ on your keyboard to exit insert mode, then type :x, and press enter.
   −
[[File:Networking trb user scripts examples cli 1wire data to server script.png.png|border|left]]
+
[[File:Networking trb user scripts examples cli 1wire data to server script.png.png|border|class=tlt-border]]
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
  −
 
      +
Run the command: '''<code>‘chmod 777 <filename>’</code>''' to make the script executable on your end.
   −
  −
  −
Run the command: '''<code>‘chmod 777 <filename>’</code>''' to make the script executable on your end.
      
==== Code explanation ====
 
==== Code explanation ====
 
This line uses '''‘ubus’''' command to call the '''‘ioman.gpio.onewire’''' service and execute the '''‘status’''' command. The output of this command is saved to the ''status'' variable.
 
This line uses '''‘ubus’''' command to call the '''‘ioman.gpio.onewire’''' service and execute the '''‘status’''' command. The output of this command is saved to the ''status'' variable.
[[File:Networking trb user scripts cli code explanation1.png|left]]
+
[[File:Networking trb user scripts cli code explanation1.png|border|class=tlt-border]]
 
  −
 
  −
 
  −
 
  −
 
  −
 
      
This block of code extracts the value of the '''‘value’''' parameter from the ‘status’ output using '''‘grep’'''and '''‘sed’''' and stores it in the ‘value’ variable.
 
This block of code extracts the value of the '''‘value’''' parameter from the ‘status’ output using '''‘grep’'''and '''‘sed’''' and stores it in the ‘value’ variable.
    
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|left]]
+
[[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|left]]
+
[[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.
    
After that, it extracts the sensor ID from the sensor directory path using the ‘basename’ command and stores it in the ‘sensor_id’ variable.
 
After that, it extracts the sensor ID from the sensor directory path using the ‘basename’ command and stores it in the ‘sensor_id’ variable.
[[File:Networking trb user scripts cli code explanation4.png|left]]
+
[[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.
    
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]]
+
[[File:Networking trb user scripts cli code explanation5.png|left|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.
 
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|left]]
 
[[File:Networking trb user scripts cli code explanation6.png|left]]
  −
  −
  −
  −
      
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.
 
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.
Line 177: Line 114:  
=== Output ===
 
=== Output ===
 
[[File:Networking trb user scripts HTTP listener screenshot.png|left|800x800px]]
 
[[File:Networking trb user scripts HTTP listener screenshot.png|left|800x800px]]
  −
  −
  −
  −
  −
  −
  −
  −
  −
  −
  −
  −
  −
  −
      
Run the script by entering the file path of the file or '''./<filename>.sh''' if you are in the same directory.
 
Run the script by entering the file path of the file or '''./<filename>.sh''' if you are in the same directory.