When I run this Python3 script from the command line or from Thonny I get correct results. When I run it through crontab the variables ipaddress an ssid stay empty.
Can anyone tell me why? Any suggestions to solve it?
import dweepy, os
ipaddress = os.popen("ifconfig wlan0 | grep 'inet' | awk '/inet / {print $2}'").read()
ssid = os.popen("iwconfig wlan0 | grep 'ESSID' | awk '{print $4}' | awk -F\\\" '{print $2}'").read()
data = ssid[:-1] + ' ' + ipaddress[:-1]
dweepy.dweet_for('NorthWestern', {'here I am':data})
This script should let me know the ip address and the SSID of the wifi to which my headless Pi is connected.
Edit: this is the line in crontab:
* * * * * python3 /home/pi/PythonON5MF/send_ip_v001.py &
hostname -I
to get the IP address? The "&" in cron seems superfluous for a script that runs once.