/*
Sample program to manage relays a receive messages
Copyright (C) 2017 Chocron J.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LiquidCrystal.h>
#include "abtoo.h"
// Relays
int r1 = 16; // GPIO16
int r2 = 5; // GPIO5
int r3 = 4; // GPIO4
// LCD
int rs = 0; // GPIO0
int en = 2; // GPIO2
int d4 = 14; // GPIO14
int d5 = 12; // GPIO12
int d6 = 13; // GPIO13
int d7 = 15; // GPIO15
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// WiFi
char* ssid = "MYSSID";
char* password = "MYPASSWORD";
AbetooIno abtoino;
// Message received callback
void messageReceived(String message)
{
if (message == "r1on")
{
digitalWrite(r1, LOW);
}
else if (message == "r1off")
{
digitalWrite(r1, HIGH);
}
else if (message == "r2on")
{
digitalWrite(r2, LOW);
}
else if (message == "r2off")
{
digitalWrite(r2, HIGH);
}
else // text message
{
lcd.setCursor(0,1);
lcd.print(message+" ");
}
}
void setup() {
// Initialize pins
pinMode(rs, OUTPUT);
pinMode(en, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(d5, OUTPUT);
pinMode(d6, OUTPUT);
pinMode(d7, OUTPUT);
// Initialize LCD
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Abetoo IoT");
lcd.setCursor(0,1);
lcd.print("Arduino Library");
Serial.begin(9600);
delay(10);
// Initialize Relay's pins
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
abtoino.init("uuid1", "-TbVO-rqdA0iWg6-gWh0eeQ636243460528994051#735acf9cd6eda96e66ee3858496dca59d750aff1", 1, messageReceived);
}
void loop()
{
abtoino.abetooloop();
}
Comments