Interactive arduino internet-of-things

I’ve written before about my Math and Computational Methods for Physicist course and how we’re doing a cool Arduino-based Internet of Things project. I’ve been brainstorming some new things we might do with that project and I wanted to see if you, dear reader, might have some suggestions/observations/complaints/whatever.

First an update on the database and our prototype. I haven’t added much to the database. Really only a dashboard list for the admin (me) showing the total number of measurements for each machine and when the last measurement was. It turns out that even though I fixed the pretty common wifi freeze with the watchdog approach, it still goes down about twice a week. I’m not really sure what’s up with that. The most recent time it happened I didn’t notice for about a day so when I went to look at it I noticed it was pretty hot. Unplugging it for 10 seconds or so and then replugging it seems to have fixed it for now. Any thoughts on how I can figure out what causes those very intermittent problems would be greatly appreciated. The class has devoted one lab to Arduinos so far and they all got to the point where they were measuring and calibrating temperature and controlling an LED. Pretty good for 90 minutes. We meet again about it this coming week when I’m hoping they’ve all found a “client” that they can program the arduino for.

Using a clock

The first new idea is to deal with client requests that are time-based. Something like “every night at midnight check the XXXX and report” as opposed to what we already have: “every Y minutes do something.” The arduino has a millisecond timer on it, but you can’t trust it to know in absolute terms what time it is. So at first I thought we couldn’t handle those requests. But then I remembered that we have a working wifi card on all of these! I figure we can just have it check the absolute time on some time server somewhere and at most be off by Y minutes. That’ll likely satisfy those sorts of clients (at least I hope so).

Interrupts

Already a few potential clients have asked for things like “every time the door opens measure XXX and report.” If they can handle a resolution of Y minutes, then we’re all set. Otherwise we’ll have to use the built-in interrupt stuff for arduinos. Then if the door opens an interrupt will be thrown and we’ll execute the whole “measure XXX and hook up to the internet” code.

Make a measurement if we say so

This is the one that I would really like some advice on. Some students and I were brainstorming how we might communicate to the arduino to make a measurement. Really this would be an extension of the “using a clock” idea above. We’re thinking of updating the database web site so that the owner of the machine (which is currently defined as the person who most recently updated the code for that machine) could update a page with something like “yes” or “no” returned so that the machine would check that page first (every Y minutes, say) before deciding whether to do anything else. We could, of course, get more complicated with various messages triggering lots of different responses from the machine. The limit would be the storage on the arduino (20 totally different codes stored might not be possible, for example) but I think we can still do some cool stuff.

I guess my question is: is this the right way to go about it? I read a lot about making the arduino basically a web page server so that you can go to it and ask for things. That’s the bulk of the pages you get if you search for “arduino internet of things” so I know it’s pretty popular. My problem is that it seems like it’s asking the arduino to do quite a lot, and essentially be fully on (as opposed to a boring “pause” loop) all the time. I figure this approach saves a lot of that, but maybe I’m missing something.

So, we’d love your help. If you have any ideas/hare-brained-schemes/concerns/anecdotes/love-letters-to-mathematica let us know in the comments below. Here are some starters for you:

  • I’m in this class and I’m really excited about this project. What Andy forgot to add was . . .
  • I’m in this class and I hate it. What I’d love is if someone made it clear to Andy that this is a dumb project so we don’t have to do it.
  • I’m in the HUWebApps group that Andy talked about here and I think this could be some fun work for us. One thought I had was . . .
  • I think these new ideas are really cool. One thing I’d be a little worried about is . . .
  • I think that some of these ideas are really bad, damage-people-for-life bad! Here’s a better way to go about it . . .
  • I’ve done some similar work <snark>thanks for linking to me</snark> and I’d suggest you read this, this, and this.
  • I run my arduino as a web server and it works great! You should really switch because . . .
  • I run my arduino as a web server and it sucks! I’m thinking of switching to how you do it, can I use your database?
Advertisements

About Andy "SuperFly" Rundquist

Professor of physics at Hamline University in St. Paul, MN
This entry was posted in arduino, HUWebApps. Bookmark the permalink.

6 Responses to Interactive arduino internet-of-things

  1. Hi Andy. About the connection timeouts, have you seen this: http://community.blynk.cc/t/cc3000-issues/422/3 ? Looks like it could be a flaw with the chip..?

    • Andy "SuperFly" Rundquist says:

      I think they’re talking about the problem I “fixed” with the watchdog stuff. Without that fix it would freeze every few hours.

  2. gcschmit says:

    If you end up needing a higher precision clock, there is a data logging shield with a real-time clock: . I’ve used this before and it has worked well.

  3. Andy "SuperFly" Rundquist says:

    Great comment from a facebook connection:

    Clock: Consider a DS1302 clock or something similar. A little extra hardware, but it can keep decent time. The main benefit here is that if wifi is not available/goes down/whatever, you can still keep time. You can periodically check in with a time server to reset the clock if necessary.

    Interrupts: I’ve used interrupts for doing light fading/dimming on an AC line. The interrupt was fired at every cross over, so about 120 times/second. So, your example of a door opening should be easily handled. The trick is to keep the interrupt code fast and simple. I usually just use it set a flag that is then processed in the “regular” code.

    Making a measurement: Consider something like MQTT which allows you do to very simple messaging. You’ll have to set up an MQTT server elsewhere on something like a Pi or computer. You could then publish a list of things to measure. The Arduino could hold that list in memory (or EEPROM if you want it available after a restart). Whenever you change the list, it will get pushed to the Arduino. This would be very lightweight. (Maybe, I haven’t done that on an Arduino, so I don’t know how involved it is.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s