How To Make IoT Messaging with BashShell
Create new file with extension .sh ..
As you know the first line of Bash Script start with this
so we can collect this information with Shell Script.
As you know the first line of Bash Script start with this
#!/bin/bashokay, let's say we want collect information of our IoT like Memory and IP Address etc..
so we can collect this information with Shell Script.
# Get Used Memory
um=$(free -h | grep Mem | awk ' { print $3 } ')
# Get Free Memory
fm=$(free -h | grep Mem | awk ' { print $2 } ')
# Get Local IP Address
ipadd=$(ifconfig wlp3s0b1 | grep 'inet ' | awk '{print $2}')
# Get Public IP Address
pip=$(curl iblo.esy.es)
Okay We Are Done, We collect all information that we need to save, so we need name for our IoT, let's make it complex .
if we save data again the output looks like this :
IoTName="rasp5289166"Now we put all Variables in one Variable
URL="http://www.iblo.esy.es/save/data/?iot=$IoTName&PuIp=$pip&ip=$ipadd&UsedMem=$um&FreeMem=$fm"Now let's Save our Data
output=$(curl -X POST $URL)the output variable should be like this :
New Name http://www.iblo.esy.es/load/data/?iot=rasp5289166Note it respond with "New Name" and the link of your saved data.
if we save data again the output looks like this :
Overwritten http://www.iblo.esy.es/load/data/?iot=rasp5289166
When you use awk, grep is redundant:
ReplyDeleteum=$(free -h | awk '/Mem/ { print $3 }')