need help getting a bash file to curl to thingspeak -> Twitter (reworded question)


 

Stuart-mdnuts

New member
Hello,

I used the tweet my meat thread to successfully tweet an account when alarms have triggered.

Great

But I also want to periodically tweet the status of things. I took that and put it into a bash file inside /mnt/mmblk0p4/ and made it executable. I do not get any tweets from it running it via sh test.sh. if I add --write-output to it i'll see a 200 response. what doesn't make sense to me is why will i get tweets when i test via alarm script but not from a bash script when i get the 200 response?

Any thoughts?

Thank you
Stuart
 
Last edited:
Can you post the contents of the bash script. Be sure to change your API keys to XXXX when posting.
 
Can you post the contents of the bash script. Be sure to change your API keys to XXXX when posting.
absolutely, it was this. i later removed the status part and just tried "test" and couldn't get it to tweet. I really don't get it, it worked find in alarm script and I get a 200 ok message. retested alarms and no issue - so the key was ok.

If I could get thingspeak working that would be ideal, I'd prefer to send updates every half hour rather than one hour

Code:
#!/bin/sh
curl -q -k -d "api_key=<mykey>" -d "status=$pn Alert: Alarm $al_type outside threshold $al_thresh, currently $pcurr" https://api.thingspeak.com/apps/thingtweet/1/statuses/update
 
Last edited:
Maybe I'm missing something, but it seems like you're not sending your stats2 data to the thingtweet app.

The cron based script should look something like:

Code:
#!/bin/sh
#field1 = set point
#field2 = lid state
#field3 = fan speed
#field4 = probe0 temp
#field5 = probe1 temp
#field6 = probe2 temp
#field7 = probe3 temp

stats=$(lmclient \
    | tr "{," "\n" \
    | grep -e set -e lid -e \"c\" \
    | awk -F: '{print $2}' \
    | sed 's/null/0/g')

# only let the lid be 0 or 100
lidstate=$(echo $stats | awk '{print $2}')
if [ "$lidstate" -gt "0" ]
then
stats=$(echo $stats | awk '$2 {$2=100; print}')
fi

stats2=`echo $stats | awk '{print "\\n" "Target Temp: " $1 "\\n" "Lid State: " $2 "\\n" "Fan Speed: " $3 "\\n" "Pit Temp: " $4 "\\n" "probe1: " $5 "\\n" "probe2: " $6 "\\n" "probe3: " $7 "\\n"}'`

curl -q -k -d "api_key=<mykey>" -d "$stats2" https://api.thingspeak.com/apps/thingtweet/1/statuses/update
 
Maybe I'm missing something, but it seems like you're not sending your stats2 data to the thingtweet app.

The cron based script should look something like:

Thank you for replying. I probably wasn't all that clear.

I couldn't get thingtweet to work when called from a bash script so I tried IFTTT - which was what I posted above after modifying your code that seems to work for you from a bash script.

I don't get it. I tried this tonight
- copied from alarm script (which works repeatedly) - put into bash file - it ran and tweeted (no stats of course)
- put the alarm script copy into the script that parses out the stats - runs without error but no tweet
- tried to run the alarm script that was in it's own bash file again - runs without error but no tweet.
- test from alarms again - tweets without issue
- back to the alarm script that is in the bash file - runs without error but no tweet.
 
What path are you storing the script to on the HM?

What does your cron entry look like?
It's in /mnt/mmblk0p4

At this point I'm just running from the directory itself not even trying Cron.
-the file is set to executable
-even tried permissions of 777

What's throwing me is getting the 200 response, I'd expect an error of some sort not 200. Even then, why work really periodically
 
Decided to test it out and realized that "status=" was missing

Code:
curl -dq "api_key=XXX" -d "status=$stats2" https://api.thingspeak.com/apps/thingtweet/1/statuses/update

You'll also want to change your awk statement from \\n to \r\n in order for the linebreaks to appear properly on twitter

RzAuYh1l.png
 
ok, i figured it out.

I was definitely missing the status= there, but I had also copied what worked from the alarm script, put that in a bash script and it would fire - once.

What I figured out this morning - after spending an embarrassingly long amount of time on this - is thingtweet apparently won't send the same exact tweet a second time in a row. You can test this by hitting the same alarm test twice and see how many tweets you get for it. Earlier I would test say probe 1 low, then probe 1 high then probe 1 low again and I would get all the tweets. But hit alarm test twice on say probe 1 high - you'll only get one tweet.

it's probably listed really clearly in thingspeak's docs that I didn't see.

:sigh: thank you for taking a look at it Steve, what I'll do is just add to that existing "send periodically" thread and append this part as well as IFTTT's code.
 
It's actually twitter that enforces the de-duplication of tweets. You can get around it by adding adding a timestamp or something else that will be unique with each message.
 
Thanks for that tip. Almost finished with it. is the start time value stored anywhere? I didn't see it on the lmclient page. there is a time indication but i'm assuming that is current time.
 
No, you'll need to create a timestamp. Something like this:

Code:
date=$(date -d 'now')

stats2="$date $(echo $stats | awk '{print "\r\n" "Target Temp: " $1 "\r\n" "Lid State: " $2 "\r\n" "Fan Speed: " $3 "\r\n" "Pit Temp: " $4 "\r\n" "probe1: " $5 "\r\n" "probe2: " $6 "\r\n" "probe3: " $7 "\r\n"}')"
 
yeah i
No, you'll need to create a timestamp. Something like this:

Code:
date=$(date -d 'now')

stats2="$date $(echo $stats | awk '{print "\r\n" "Target Temp: " $1 "\r\n" "Lid State: " $2 "\r\n" "Fan Speed: " $3 "\r\n" "Pit Temp: " $4 "\r\n" "probe1: " $5 "\r\n" "probe2: " $6 "\r\n" "probe3: " $7 "\r\n"}')"

Yeah i got that ok, i was just thinking it'd be helpful to list the total cook time - or at least the time heatermeter started for the day/period.
 

 

Back
Top