Example program - taking a photo with a webcam and sending it via text message

After receiving plain text messages from my robot I thought it would be useful to have the robot take a photo then text that photo to me. It turns out that when you send a send a text message with a photo, video, url link, or emoji, you are sending an MMS (multi-media message service) message. Twilio’s API supports this, but attached image must be hosted on a website and that url must be passed to Twilio. Dropbox is free and relatively easy to use to create this shareable link.

The example code can be downloaded here: example_robot_programs/text_messaging/mms_example at main · tormach/example_robot_programs · Git

If you’re reading this post and haven’t seen the post on sending an SMS message, I recommend reading and trying that first. The set up for MMS is similar to the setup for SMS, but with the additional requirement that you create a Dropbox account and get a Dropbos API key. There are great instructions on getting a Dropbox API key here: How to Get Your Dropbox API Access Token • 99rabbits

The basic idea is:

  1. OpenCV is used to take a photo using any attached USB camera
  2. That photo is uploaded to Dropbox and a shared link (url) is returned
  3. Twilio is used to send a text message with the shared link included in the message body
  4. The message shows up on your phone with the photo embedded in it

Like other examples I’ve posted, this is just a simple proof of concept. It would work for anyone wanting to experiment with texting photos from the robot. There is no error checking, the photos aren’t garbage-collected (they litter your working directory and your Dropbox account), there’s no notification that something went wrong if, for instance, your webcam came unplugged, etc. Feel free to suggest improvements or submit pull requests to the repository if you have the time and interest.

1 Like