Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2020
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.87 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # sends modem data to mqtt server
  4. # install mqtt client: opkg install mosquitto-client
  5. # copy to /etc/config/
  6. # chmod +x /etc/config/modem_mqtt.sh
  7.  
  8. # in /etc/rc.local add
  9. # /etc/config/modem_mqtt.sh &
  10. # before  exit 0
  11.  
  12.  
  13. ROOTER=/usr/lib/rooter
  14.  
  15. CURRMODEM=1
  16. COMMPORT=/dev/ttyUSB1
  17. #Place here your mosquitto server IP
  18. #MQTTSERVER=192.168.1.112
  19. MQTTSERVER=odroid
  20.  
  21. get_sierra() {
  22.     OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "sierrainfo.gcom" "$CURRMODEM")
  23.  
  24.     O=$($ROOTER/common/processat.sh "$OX")
  25.     O=$(echo $O)
  26. }
  27.  
  28. while true
  29.     do
  30. get_sierra
  31.  
  32. Oup=$(echo $O | tr 'a-z' 'A-Z')
  33. IPV4=$(ifconfig wwan0 | grep "inet addr:" | sed 's/addr://g' | awk '{print $2}')
  34. IPV6=$(ifconfig wwan0 | grep "inet6 addr:" | sed 's/addr://g' | awk '{print $2}' | head -1)
  35. RXBYTES=$(ifconfig wwan0 | grep "RX bytes:" | sed 's/bytes://g' | awk '{print $2}')
  36. TXBYTES=$(ifconfig wwan0 | grep "TX bytes:" | sed 's/bytes://g' | awk '{for(i=1;i<=NF;i++)if($i~/TX/)print $(i+1)}')
  37. SINR=$(echo "$OX" | awk '{for(i=1;i<=NF;i++)if($i~/SINR/)print $(i+2)}')
  38.  
  39. if [ "x$IPV4" != "x" ]; then
  40.     IPV4=",\"IPV4\":\"$IPV4\""
  41. else
  42.     IPV4=""
  43. fi
  44.  
  45. if [ "x$RXBYTES" != "x" ] && [ "$RXBYTES" != "0" ]; then
  46.     RXBYTES=",\"RX\":$RXBYTES"
  47. else
  48.     RXBYTES=""
  49. fi
  50.  
  51. if [ "x$TXBYTES" != "x" ] && [ "$TXBYTES" != "0" ]; then
  52.     TXBYTES=",\"TX\":$TXBYTES"
  53. else
  54.     TXBYTES=""
  55. fi
  56.  
  57. if [ "x$IPV6" != "x" ]; then
  58.     IPV6=",\"IPV6\":\"$IPV6\""
  59. else
  60.     IPV6=""
  61. fi
  62.  
  63. if [ "x$SINR" != "x" ] && [ "$SINR" != "-" ]; then
  64.     SINR=",\"sinr\":$SINR"
  65. else
  66.     SINR=""
  67. fi
  68. TEMP=$(sed '30q;d' /tmp/status1.file | awk '{print substr($0, 1, length($0)-3)}')
  69. if [ "$TEMP" != "-" ] && [ "x$TEMP" != "x" ]; then
  70.         TEMP=",\"temp\":$TEMP"
  71. else
  72.         TEMP=""
  73. fi
  74. SIGNAL=$(sed '3q;d' /tmp/status1.file | awk '{print substr($0, 1, length($0)-1)}')
  75. if [ "$SIGNAL" != "-" ] && [ "x$SIGNAL" != "x" ]; then
  76.         SIGNAL=",\"signal\":$SIGNAL"
  77. else
  78.         SIGNAL=""
  79. fi
  80. RSSI=$(sed '4q;d' /tmp/status1.file | awk '{print $1}')
  81. if [ "$RSSI" != "-" ] && [ "$xRSSI" != "x" ]; then
  82.         RSSI=",\"rssi\":$RSSI"
  83. else
  84.         RSSI=""
  85. fi
  86. RSRQ=$(sed '18q;d' /tmp/status1.file | awk '{print $1}')
  87. if [ "$RSRQ" != "-" ] && [ "x$RSRQ" != "x" ]; then
  88.         RSRQ=",\"rsrq\":$RSRQ"
  89. else
  90.         RSRQ=""
  91. fi
  92. RSRP=$(sed '19q;d' /tmp/status1.file | awk '{print $1}')
  93. if [ "$RSRP" != "-" ] && [ "x$RSRP" != "x" ]; then
  94.         RSRP=",\"rsrp\":$RSRP"
  95. else
  96.         RSRP=""
  97. fi
  98.         mosquitto_pub -h $MQTTSERVER -i horus -t "modem/status" -m "{\"name\":\"$(sed '5q;d' /tmp/status1.file)\",\
  99. \"provider\":\"$(sed '6q;d' /tmp/status1.file | awk '{print $1}')\",\
  100. \"connection\":\"$(sed '7q;d' /tmp/status1.file)\",\
  101. \"band\":\"$(sed '29q;d' /tmp/status1.file | sed 's/aggregated with:<br \/>/+ /g')\",\
  102. \"proto\":\"$(sed '31q;d' /tmp/status1.file)\"\
  103. $IPV4\
  104. $IPV6\
  105. $RXBYTES\
  106. $TXBYTES\
  107. $TEMP\
  108. $SIGNAL\
  109. $SINR\
  110. $RSSI\
  111. $RSRQ\
  112. $RSRP\
  113. }"
  114.  
  115. sleep 30
  116. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement