This repository has been archived by the owner on Feb 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,077 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <Arduino.h> | ||
#include <mqttsn-messages.h> | ||
|
||
#define TOPIC "test" | ||
|
||
MQTTSN mqttsn; | ||
|
||
uint16_t u16TopicID; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial1.begin(9600); | ||
} | ||
|
||
void loop() { | ||
uint8_t index; | ||
|
||
CheckSerial(); | ||
delay(2000); | ||
|
||
if (mqttsn.wait_for_response()) { | ||
return; | ||
} | ||
|
||
if (!mqttsn.connected()) { | ||
mqttsn.connect(0, 10, "arduino"); | ||
return; | ||
} | ||
|
||
u16TopicID = mqttsn.find_topic_id(TOPIC, &index); | ||
if (u16TopicID == 0xffff) { | ||
mqttsn.register_topic(TOPIC); | ||
return; | ||
} | ||
|
||
char str[50] = "Hello World!"; | ||
mqttsn.publish(0, u16TopicID, str, strlen(str)); | ||
} | ||
|
||
void MQTTSN_serial_send(uint8_t *message_buffer, int length) { | ||
Serial1.write(message_buffer, length); | ||
Serial1.flush(); | ||
} | ||
|
||
void MQTTSN_publish_handler(const msg_publish *msg) { | ||
|
||
} | ||
|
||
void MQTTSN_gwinfo_handler(const msg_gwinfo *msg) { | ||
} | ||
|
||
void CheckSerial() { | ||
uint16_t cnt = 0; | ||
uint8_t buffer[512]; | ||
uint8_t *buf = &buffer[0]; | ||
|
||
while (Serial1.available()) { | ||
buffer[cnt++] = Serial1.read(); | ||
} | ||
|
||
if (cnt > 0) { | ||
for (int i = 0; i < cnt ; i++) { | ||
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(" "); | ||
} | ||
Serial.println(""); | ||
mqttsn.parse_stream(buf, cnt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
(c) Diego Fernández <[email protected]> | ||
Originally published on https://github.com/ESIBot/MQTT-SN-Arduino | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <mqttsn-messages.h> | ||
|
||
#define TOPIC "test" | ||
|
||
MQTTSN mqttsn; | ||
|
||
uint16_t u16TopicID; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial1.begin(9600); | ||
} | ||
|
||
void loop() { | ||
uint8_t index; | ||
|
||
CheckSerial(); | ||
delay(2000); | ||
|
||
if (mqttsn.wait_for_response()) { | ||
return; | ||
} | ||
|
||
if (!mqttsn.connected()) { | ||
mqttsn.connect(0, 10, "arduino"); | ||
return; | ||
} | ||
|
||
u16TopicID = mqttsn.find_topic_id(TOPIC, &index); | ||
if (u16TopicID == 0xffff) { | ||
mqttsn.register_topic(TOPIC); | ||
mqttsn.subscribe_by_name(0, TOPIC); | ||
return; | ||
} | ||
} | ||
|
||
void MQTTSN_serial_send(uint8_t *message_buffer, int length) { | ||
Serial1.write(message_buffer, length); | ||
Serial1.flush(); | ||
} | ||
|
||
void MQTTSN_publish_handler(const msg_publish *msg) { | ||
|
||
} | ||
|
||
void MQTTSN_gwinfo_handler(const msg_gwinfo *msg) { | ||
} | ||
|
||
void CheckSerial() { | ||
uint16_t cnt = 0; | ||
uint8_t buffer[512]; | ||
uint8_t *buf = &buffer[0]; | ||
|
||
while (Serial1.available()) { | ||
buffer[cnt++] = Serial1.read(); | ||
} | ||
|
||
if (cnt > 0) { | ||
for (int i = 0; i < cnt ; i++) { | ||
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(" "); | ||
} | ||
Serial.println(""); | ||
mqttsn.parse_stream(buf, cnt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define API_DATA_LEN 20 | ||
#define API_PAY_LEN (API_DATA_LEN + 5) | ||
#define API_FRAME_LEN (API_DATA_LEN + 9) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
MQTTSN KEYWORD1 | ||
|
||
find_topic_id KEYWORD2 | ||
wait_for_response KEYWORD2 | ||
connected KEYWORD2 | ||
parse_stream KEYWORD2 | ||
searchgw KEYWORD2 | ||
connect KEYWORD2 | ||
willtopic KEYWORD2 | ||
willmsg KEYWORD2 | ||
register_topic KEYWORD2 | ||
publish KEYWORD2 | ||
subscribe_by_name KEYWORD2 | ||
subscribe_by_id KEYWORD2 | ||
unsubscribe_by_name KEYWORD2 | ||
unsubscribe_by_id KEYWORD2 | ||
pingreq KEYWORD2 | ||
pingresp KEYWORD2 | ||
disconnect KEYWORD2 | ||
|
||
FLAG_DUP LITERAL1 | ||
FLAG_QOS_0 LITERAL1 | ||
FLAG_QOS_1 LITERAL1 | ||
FLAG_QOS_2 LITERAL1 | ||
FLAG_QOS_M1 LITERAL1 | ||
FLAG_RETAIN LITERAL1 | ||
FLAG_WILL LITERAL1 | ||
FLAG_CLEAN LITERAL1 | ||
FLAG_TOPIC_NAME LITERAL1 | ||
FLAG_TOPIC_PREDEFINED_ID LITERAL1 | ||
FLAG_TOPIC_SHORT_NAME LITERAL1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name=MQTT-SN for Arduino | ||
version=0.1 | ||
author=John Donovan <https://bitbucket.org/MerseyViking/>, Boris <http://dmcinfo.com>, Diego Fernández <[email protected]>, Giampaolo Mancini <[email protected]> | ||
maintainer=Giampaolo Mancini <[email protected]> | ||
sentence=Simple MQTT-SN library for Arduino. | ||
paragraph=An implementation of the MQTT-SN client protocol for AVR-based microcontrollers. | ||
category=Communication | ||
url=https://github.com/kiotlog/mqttsn-arduino | ||
architectures=* | ||
includes=mqttsn-messages.h |
Oops, something went wrong.