No one is reading this, but I found an error in my suggestion.

The ubidots line should read:

ubidots -t $TOKEN -d $DEVICE set '{"free-memory":'$freeMem'}'