Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Arduino Security Doorbell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
antony.adewunmi-jones
Arduino Security Doorbell
Commits
a73e055c
Commit
a73e055c
authored
Jan 23, 2024
by
antony.adewunmi-jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
feeed289
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
ARDUINOSUBSCRIBE
ARDUINOSUBSCRIBE
+89
-0
No files found.
ARDUINOSUBSCRIBE
0 → 100644
View file @
a73e055c
#include <ArduinoMqttClient.h>
#include <WiFiNINA.h>
#include "pass.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID
char pass[] = SECRET_PASS; // your network password
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);
const char broker[] = "test.mosquitto.org";
int port = 1883;
const char AAJtopic[] = "BUTTON ACTIVATED";
const char SOUNDtopic[] = "SOUND DETECTED";
const char LIGHTtopic[] = "POSSIBLE MOVEMENT DETECTED";
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
//WIFI
Serial.println("Attempting to connect to SSID: ");
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("Couldn't get a wifi connection");
while (true);
}
//FAILED
Serial.print(".");
delay(5000);
}
Serial.println("You're connected to the network");
Serial.println();
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT broker!");
Serial.println();
//CALLBACK
mqttClient.onMessage(onMqttMessage);
Serial.print("Subscribing to topic: ");
Serial.println(AAJtopic);
Serial.println();
Serial.print("Subscribing to topic: ");
Serial.println(SOUNDtopic);
Serial.println();
Serial.print("Subscribing to topic: ");
Serial.println(LIGHTtopic);
Serial.println();
// TOPIC SUBSCRIPTION
mqttClient.subscribe(AAJtopic);
mqttClient.subscribe(SOUNDtopic);
mqttClient.subscribe(LIGHTtopic);
Serial.println();
}
void loop() {
//POLL BROKER TO STAY CONNECTED
mqttClient.poll();
}
//ON MESSAGE RECIEVED, PRINT IT
void onMqttMessage(int messageSize) {
Serial.print(mqttClient.messageTopic());
Serial.println();
Serial.println();
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment