Next Thing CHiP as a Twitter Bot

twitter-logoThere was a post that came across on Medium recently, How to Make a Twitter Bot in Under an Hour.  It’s pretty straight forward, though it seems to be pretty geared towards non “techie” types, mostly because it’s geared towards people making the bot on a Mac and it uses something called Heroku to run the bot.  Heroku seems alright, except that this sort of feels like an abuse of their free tier, and it’s not free for any real projects.

I already have a bunch of IOT stuff floating around that’s ideal for running periodic services.  I also have a VPS is I really wanted something dedicated.  So I adapted the article for use in a standard Linux environment.  I used one of my CHiPs but this should work on a Raspberry Pi, an Ubuntu box, a VPS, or pretty much anything running Linux.

The first part of the article is needed, set up a new Twitter account, or use one you already have if you have extras.  Go to apps.twitter.com, create an app and keys, keep it handy.

Install git and python and python’s twitter extension.

sudo apt-get install git

sudo apt-get install python-twitter

This should set up everything we’ll need later.  Once it’s done, close the repository.

git clone https://github.com/tommeagher/heroku_ebooks.git

This should download the repository and it’s files.  Next it’s time to set up the configuration files.

cd heroku_ebooks

cp local_settings_example.py local_settings.py

pico local_settings.py

This should open up an editor with the settings file open.  It’s pretty straight forwards, you’ll need to copy and paste the keys from Twitter into the file, there are 4 of them total, make sure you don’t leave any extra spaces inside the single quotes.  You’ll also need to add one or more accounts for the bot to model itself after.  You’ll also need to change DEBUG = TRUE to DEBUG = FALSE as well as adding your bot’s username to the TWEET_ACCOUNT=” entry at the bottom.

Once that is all done do a Control+O to write out the file and Control+X to exit.  Now it’s time to test out the bot with the following…

python ebooks.py

It may pause for a second while it does it’s magic.  If you get the message ” No, sorry, not this time.” it means the bot decided not to tweet, just run the command again until it tweets, since we’re testing it at the moment.  If it worked, it should print a tweet to the command line and the tweet should show up in the bot’s timeline.  If you get some errors, you may need to do some searching and troubleshooting, and double check the settings file.

Next we need to automate the Twitter Bot Tweets.  This is done using Linux’s built in cron.  But first we need to make our script executable.

 chmod 755 ebooks.py

Next, enter the following….

sudo crontab -e

Then select the default option, which should be nano.  This will open the cron scheduler file.  You’ll want to schedule the bot to run according to whatever schedule you want.  Follow the columns above as a guide.  For example:

# m h  dom mon dow   command

*/15 * * * * python /home/chip/heroku_ebooks/ebooks.py

m = minutes = */15 = every 15 minutes of an hour (0, 15, 30, 45)

h = hour = * (every hour)

dom = day of month = * = every day and so on.  The command to run, in this case, is “python /home/chip/heroku_ebooks/ebooks.py”.  If you’re running this on a Raspberry Pi, or your own server, you will need to change “chip” to be the username who’s directory has the files.  Or, if you want to put the files elsewhere, it just needs to b e the path to the files.  For example, on a Raspberry Pi, it would be “python /home/pi/heroku_ebooks/ebooks.py”.

If everything works out, the bot should tweet on schedule as long as the CHIP is powered on and connected.  Remember, by default the bot only tweets 1/8th of the time when the script is run (this can be adjusted in the settings file), so you may not see it tweet immediately.

This is also a pretty low overhead operation, you could conceivably run several Twitter Bots on one small IOT device, with a staggered schedule even.  Simply copy the heruko_ebooks directory to a new directory, change the keys and account names and set up a new cron job pointing to the new directory.

NextThing CHIP and Raspberry Pi Zero

Raspberry Pi Zero and Next Thing's CHIPI’ve already briefly discussed my NextThing CHIP computers before. A few weeks ago I was purchasing a Raspberry Pi 3 and found that the store had Pi Zeros in stock as well, so I tossed one on because, hey, $5, and they are apparently hard to find.

These two little devices are pretty similar, but at the same time so different.

Both are small computers, not just microcontrollers like an Arduino, but little Linux machines. Both have GPIO pins, both can be used as a regular “desktop” if you wanted, both cost less than $10… Mostly…

Raspberry Pi ZeroThe cost is where things get tricky, especially for the Raspberry Pi Zero. Upfront, the Pi Zero is only $5, which looks great on paper, and it’s still pretty cheap. That five dollars gets you a small flat circuit board with a few low profile ports on it. Chances are you’ll need a power supply, if you want to be able to configure it at all you’ll also need a way to plug a standard USB hub for keyboard and mouse into a micro USB port. The display out is a mini HDMI port, which you’ll likely also need an adaptor for. The Pi Zero also doesn’t have any sort of case on it. All of this is stuff that you may or may not need, you might have on hand, or, if you’re programming many Zeros, you can reuse the adapters and parts on all of the Pi Zeros you want, once configured.

The point is, after picking up even some cheap accessories, you’re probably looking at closer to $15 for a Pi Zero. Still cheap, just not quite AS cheap.

Next Thing CHIPThe CHIP on the other hand, is $9. It has built in WiFi and Bluetooth, it comes with a little plastic case for the underside of the board, and it comes with an RCA adapter. The RCA isn’t ideal and an HDMI or VGA attachment are both coming (for $10-$15) but the RCA is usable for setting up WiFi easily for SSH or VNC access. It even has built in storage. For $9, you’re pretty much up and running right out of the box. The Pi Zero is actually kind of useless all on it’s lonesome.

That doesn’t necessarily mean the CHIP is better.

Both The Raspberry Pi Zero and Next Thing’s CHIP run an arm based version of Debian (by default, but this could be changed), thus both have a lot of common in terms of what sorts of software can be used. The CHIP however seriously lacks the Raspberry Pi’s strong community. I’ve not been able to find any decent resources for how to even use the GPIO pins, for example. I had hoped to use one of my CHIPs for a project in the garage but I’ve hit some roadblocks.

chipdesktopI’ve actually had lots of roadblocks with the CHIP. Initially they were unstable, requiring a firmware update. I’ve had many strange problems getting software packages to work properly, even when following tutorials put out by others. The closest I’ve come to finishing a project is making a homemade Alexa clone. Even after buying identical parts (Mic and Button really), after trying many fixes and even wiping the thing out and starting from scratch, I still get errors with the Audio about “Period too large”.

Everything being built in is really convenient though. I honestly haven’t come up with any ideas yet for what to do with my Pi Zero. It ends up with some goofy dongles all over it to make it functional and I have 4 full sized Raspberry Pis at my disposal for other projects. I’ve seen an interesting Game Boy emulator build using the Zero I will probably try but so far, it’s pretty much just been running quietly on my workspace counter.

Personally, I think that ultimately it comes down to there is a point where these things become too cheap or small to be useful, at least for my needs. The sorts of projects a smaller board like this may be useful for feel like they would be better suited for an Arduino. Most of the projects I use my Pis for amount to “Hardware VMs”. Single task servers that can easily be repurposed or swapped out (using SD cards).

 

Fixing my CHIP

chiplogoI mentioned getting my CHIPs from NextThing aq bit ago, but I have not really done much with them. I noticed a bit of an issue keeping them powered when I set them up and assumed I had been using a power supply that wasn’t ideal. I believe it was the one off of the Chromecast on the TV, just because it was handy. It turns out, this is not the case, there is actually an issue with the software of the CHIPs that have shipped so far. I don’t beleive it affects all of them but it’s probably a good idea to update anyway.

It’s a pretty simple process, you can review the boot repair process here. The main issue you may have is that it requires you be running Ubuntu (or really just Linux). You can get a live image and load it using a USB drive though, and being familiar with Linux is useful for working with the CHIP itself since, it runs Linux.

I’m already running Ubuntu on my Laptop, so no issues for me there, my issue was actually getting something to short the pins for FEL mode. I didn’t have any breadboard wires handy at the time. I tried a paperclip as suggested but it was too large to stick in the pin holes. Instead I found a piece of wire to strip off. The point is, almost any melat strip would work to conduct between the pins.

You may also want to try flashing the whole image. Details on this process can be found on the NextThing’s website. It’s the same basic process of fixing the boot but you need to do more work yourself instead of just running a pre made fix app.

I’ve been trying to find some good plans and ideas for my CHIPs. There are some good ideas listed here.

I wanted to try turn a USB camera into a Streaming camera, but I can’t locate any of the USB cameras I used to have.

This Web and Bluetooth Sniffing device seemed neat, though once I started looking at it it looks more like it just tracks Wireless APs in the area, I’m more interested in building a network monitor.

This homemade Amazon Echo clone is pretty neat, and seems like an interesting project to work on that involves some hardware set up as well as software.

CHIP – the $8 Computer

CHIPS!I just want to start here by saying CHIP is kind of a shitty name for a computer thing, there is no effective way to do any sort of search for “Chip computer” since “computer chip” has been a thing for eternity and gives the same results. This thing really needs a re-branding or something.

I’m also not entirely sure it’s still an $8 computer, It looks like they are charging $9 now on their website, and there is shipping costs involved.

Anyway, I’ve received two of these cheap computers from my Kickstarter contribution. I have a third one coming in 4-6 months that will include a VGA adapter. For some reason all of the peripherals are delayed. I wanted to get a December release CHIP and they offered the option to buy more once the Kickstarter ended, so I ended up with two.

CHIP is essentially a micro computer in the vein of the Raspberry Pi, though it’s more like a Pi Zero than the larger models. The main advantage the CHIP has over the Pi Zero is that it has built in WiFi and Bluetooth.

I’m not entirely sure what I want to do with these yet, though I have some ideas. They are almost as cheap as my Arduino clones (probably cheaper once I add WiFi to an Arduino), and they have a slightly more versatile interface since it’s running Debian Linux. It would be really simple to add a basic web server to this device.

The board itself seems sturdy enough. It comes in a plastic cradle that covers the bottom and three of the 4 ports are on one end which is convenient. There is a normal USB port, a micro USB for power, and a headphone style jack that has an A/V breakout cable to hook it to a monitor and speakers. The molex style battery connector is on the opposite end. The base set up only has composite output for video, the breakout cable gives you a standard Red, Yellow, White set of hook ups.

CHIP Desktop

I hooked both of my CHIPS to a TV so I could easily connect each to the WiFi in my house. Once they are online the video isn’t really necessary since I can SSH to them over the network using Putty.

On a side note, the default SSH log in information is username: root, password: chip .

I have not done much else with it yet, but it’s a nifty little device. I have a vague idea of building a Podcast radio for my car out of one with some push button controls but I have not checked if there is a CLI based podcatcher available, or even a CLI based audio player I could tie push button commands to.