Skip to content

Commit dad0536

Browse files
committed
Added support for MKR1000.
1 parent 3c579ac commit dad0536

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This example shows how to connect to Cayenne using an Arduino/Genuino MKR1000 and send/receive sample data.
2+
3+
//#define CAYENNE_DEBUG
4+
#define CAYENNE_PRINT Serial
5+
#include <CayenneMQTTMKR1000.h>
6+
7+
// WiFi network info.
8+
char ssid[] = "ssid";
9+
char wifiPassword[] = "wifiPassword";
10+
11+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
12+
char username[] = "MQTT_USERNAME";
13+
char password[] = "MQTT_PASSWORD";
14+
char clientID[] = "CLIENT_ID";
15+
16+
unsigned long lastMillis = 0;
17+
18+
void setup() {
19+
Serial.begin(9600);
20+
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
21+
}
22+
23+
void loop() {
24+
Cayenne.loop();
25+
26+
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
27+
if (millis() - lastMillis > 10000) {
28+
lastMillis = millis();
29+
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
30+
Cayenne.virtualWrite(0, lastMillis);
31+
//Some examples of other functions you can use to send data.
32+
//Cayenne.celsiusWrite(1, 22.0);
33+
//Cayenne.luxWrite(2, 700);
34+
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
35+
}
36+
}
37+
38+
//Default function for processing actuator commands from the Cayenne Dashboard.
39+
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
40+
CAYENNE_IN_DEFAULT()
41+
{
42+
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
43+
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
44+
}

src/CayenneArduinoDefines.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ Logging code adapted from Blynk library BlynkDebug.h. Copyright info below.
4141
#endif
4242
#endif
4343

44+
#include <stdio.h>
45+
#include <stdarg.h>
46+
4447
#ifdef CAYENNE_PRINT
45-
static void log(const char* PROGMEM message, ...)
48+
static void log(const char* CAYENNE_PROGMEM message, ...)
4649
{
4750
va_list args;
4851
va_start(args, message);

src/CayenneArduinoMQTTClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ class CayenneArduinoMQTTClient
115115
* Send device info
116116
*/
117117
void publishDeviceInfo() {
118+
#ifdef INFO_DEVICE
118119
publishData(SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, F(INFO_DEVICE));
120+
#endif
121+
#ifdef INFO_CPU
119122
publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, F(INFO_CPU));
123+
#endif
120124
publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, F_CPU);
121125
publishData(SYS_VERSION_TOPIC, CAYENNE_NO_CHANNEL, F(CAYENNE_VERSION));
122126
}

src/CayenneMQTTMKR1000.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
The MIT License(MIT)
3+
4+
Cayenne Arduino Client Library
5+
Copyright © 2016 myDevices
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8+
documentation files(the "Software"), to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software,
10+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
11+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
14+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
#ifndef _CAYENNEMQTTMKR1000_h
19+
#define _CAYENNEMQTTMKR1000_h
20+
21+
#include "CayenneMQTTWiFi101.h"
22+
23+
#endif

src/CayenneUtils/CayenneDefines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEAL
4747
//#define PARSE_INFO_PAYLOADS
4848

4949
//Some defines for AVR microcontrollers to allow easier usage of memory in program space.
50-
#if defined(__AVR__) || defined(ARDUINO_ARCH_SAM)
50+
#if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD)
5151
#include <avr/pgmspace.h>
5252
#define CAYENNE_USING_PROGMEM
5353
#define CAYENNE_PROGMEM PROGMEM

src/DetectDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define INFO_CPU "ATmega32U4"
3232
#elif defined(__SAM3X8E__)
3333
#define INFO_CPU "AT91SAM3X8E"
34+
#elif defined(__SAMD21G18A__)
35+
#define INFO_CPU "ATSAMD21G18"
3436

3537
/******************************************
3638
* ATtiny

0 commit comments

Comments
 (0)