-
From the Forums: Two Buttons & Two LEDs
User
smcculley
posted a useful example in the IO Forum:I have had some requests from people to share my code to talk to Adafruit IO using MQTT and being able to trigger two LED’s.
Note that I am using the latest AdafruitIO MQTT code from GitHub, as it has the latest fixes available: https://github.com/adafruit/Adafruit_MQTT_Library
In Adafruit IO, I created two feeds, called ledone and ledtwo, and added them to a group called leds. I then created a dashboard with two toggle switches, and tied them to the feeds (one to each, obviously) using the default ON and OFF button text.
Check out the post for more details. Thanks for sharing!
-
Extending the MQTT Protocol
Last month we deployed a change to Adafruit IO’s MQTT broker that allowed us to rate limit connection attempts. Although we don’t like to throttle or ban users, the change was necessary to protect Adafruit IO from abuse, and ensure the overall health of the service.
This presented a problem: How do we inform users when they have been throttled or banned? Ideally the MQTT protocol would allow for us to inform the user using a standard response, but currently the connection acknowledgement packet (
CONNACK
) has a limited set of response codes.The MQTT v3.1.1 protocol has the following values defined for the
CONNACK
packet response code:Value
Return Code Response
Description
0
0x00 Connection Accepted
Connection accepted
1
0x01 Connection Refused, unacceptable protocol version
The Server does not support the level of the MQTT protocol requested by the Client
2
0x02 Connection Refused, identifier rejected
The Client identifier is correct UTF-8 but not allowed by the Server
3
0x03 Connection Refused, Server unavailable
The Network Connection has been made but the MQTT service is unavailable
4
0x04 Connection Refused, bad user name or password
The data in the user name or password is malformed
5
0x05 Connection Refused, not authorized
The Client is not authorized to connect
6-255
Reserved for future use
The current set of codes didn’t allow us to clearly communicate the reason for disconnects to our users. We have extended the list of codes in the
CONNACK
packet to include connection throttle (0x06) and ban (0x07).Value
Return Code Response
Description
6
0x06 Connection Refused, throttled
Client has exceeded connection rate limit. Please try again later.
7
0x07 Connection Refused, banned
The client has been banned by the server administrator.
We have submitted these two new codes to the OASIS MQTT Technical Committee for comment, and we are adding support to our MQTT client libraries. If you would like to comment on these changes, please visit our IO forum and share your thoughts.
-
Using MQTT Last Will with Adafruit IO
MQTT’s last will feature allows you to ask the Adafruit IO servers to publish a message to a feed or group on your behalf. This is helpful if you would like to track when your device unexpectedly disconnects due to issues like network or power outages.
Here are some helpful tips from the IO forum that might help you if you are looking to use MQTT’s last will feature with Adafruit IO:
- The last will topic must match the normal IO MQTT topic format for feeds or group publishes.
- Last will is only published by the MQTT broker if the client fails to disconnect cleanly by sending the MQTT disconnect packet.
- Last will is only published by the MQTT broker if the the keep alive timeout expires, and the last will is not sent if your device reconnects within the timeout window. The Adafruit MQTT Library for Arduino has a default keep alive timeout of 5 minutes.
Here’s an example of setting a last will message using the Adafruit MQTT Library for Arduino:
// always set the last will message before calling connect. // if the device unexpectedly disconnects, the 'disconnect' // feed will receive the 'water monitor disconnected' message. mqtt.will("your_username_here/feeds/disconnect", "water monitor disconnected"); mqtt.connect();
-
State of IO 6.14.16
We’re continuing forward with refactoring our UI so that we can get to a point where it’s easier and quicker to build out new features. The front-end is also going to use the same API V2 that will be the future default API. As another reminder, it would be a good idea to explicitly set ‘/api/v1’ in your paths until you’re ready to upgrade to the ‘/api/v2’.
Stability of the entire system has been an ongoing project for us. We’re getting there, and continue to add more monitoring and fixes to reduce any future downtime.
Also, we’re updating our client libraries with new features and bug fixes. If you haven’t tried out the Go client library, now is a good time! If you have any suggestions for our libraries, please let us know in the forums.
Here are the stats for the past week:
* 35.6 million inserts of logged data in the last 7 days * 12578 users * 8,900 online feeds (29554 feeds total)
-
Postmortem 06.07.16
Issue
We had a brief outage this morning due to a disk space issue on our Sidekiq EC2 instance. One set of log files grew to almost 20GB, which is strange because they are setup to be rotated using
logrotate
. The files should have been limited to 700MB max. According tologrotate
status, it last ran on 6-1-16, when it should run daily viacron
.Fix
logrotate
is now setup to run hourly, and we are going have monit monitor disk space on all of our EC2 instances so we can catch this issue in the future.