IP Configuration

This commit is contained in:
Gašper Dobrovoljc
2023-03-11 15:11:03 +01:00
commit ec125f27db
662 changed files with 103738 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Ethernet ESP01 WiFi On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2017-02-21 to work with new "SmartThings v2.0" Library
///
/// Notes: The ESP-01 communicates via WiFi to your home network router,
/// then to the ST Hub, and eventually to the ST cloud servers.
///
/// The ESP-01 module has 2 GPIO pins, 0 and 2. There is no onboard
/// LED, so you will need to wire an external LED to GPIO2 for this example.
///
//*****************************************************************************
#include <SmartThingsESP8266WiFi.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
#define PIN_LED 2 //ESP-01 has 2 GPIO pins - GPIO0 (0) and GPIO2 (2)
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//ESP8266 WiFi Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid = "yourSSIDhere"; // <---You must edit this line!
String str_password = "yourWiFiPasswordhere"; // <---You must edit this line!
IPAddress ip(192, 168, 1, 209); // Device IP Address // <---You must edit this line!
IPAddress gateway(192, 168, 1, 1); //router gateway // <---You must edit this line!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1); //DNS server // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
//Create a SmartThings Ethernet ESP8266WiFi object
st::SmartThingsESP8266WiFi smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
bool isDebugEnabled; // enable or disable debug in this example
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
digitalWrite(PIN_LED, HIGH); // turn LED on
smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
digitalWrite(PIN_LED, LOW); // turn LED off
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("");
Serial.println("setup.."); // print out 'setup..' on start
}
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, LOW); // set value to LOW (off)
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
//synch up the ST cloud
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

View File

@@ -0,0 +1,142 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Ethernet ESP8266 WiFi On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2017-02-11 to work with new "SmartThings v2.0" Library
///
/// Notes: The NodeMCU ESP communicates via WiFi to your home network router,
/// then to the ST Hub, and eventually to the ST cloud servers.
///
///
//*****************************************************************************
#include <SmartThingsESP8266WiFi.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
//******************************************************************************************
//NodeMCU ESP8266 Pin Definitions (makes it much easier as these match the board markings)
//******************************************************************************************
#define LED_BUILTIN 16
#define BUILTIN_LED 16
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#define D8 15
#define D9 3
#define D10 1
#define PIN_LED LED_BUILTIN //Onboard LED
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//ESP8266 WiFi Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid = "yourSSIDhere"; // <---You must edit this line!
String str_password = "yourWiFiPasswordhere"; // <---You must edit this line!
IPAddress ip(192, 168, 1, 202); // Device IP Address // <---You must edit this line!
IPAddress gateway(192, 168, 1, 1); //router gateway // <---You must edit this line!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1); //DNS server // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
//Create a SmartThings Ethernet ESP8266WiFi object
st::SmartThingsESP8266WiFi smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
bool isDebugEnabled; // enable or disable debug in this example
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
digitalWrite(PIN_LED, LOW); // turn LED on
smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
digitalWrite(PIN_LED, HIGH); // turn LED off
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("");
Serial.println("setup.."); // print out 'setup..' on start
}
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, HIGH); // set value to HIGH (off)
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
//synch up the ST cloud
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

View File

@@ -0,0 +1,135 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Ethernet W5x00 On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2017-02-10 to work with new "SmartThings v2.0" Library
///
/// Notes: Arduino communicates with both the W5x00 and SD card using the SPI bus (through the ICSP header).
/// This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega.
/// On both boards, pin 10 is used to select the W5x00 and pin 4 for the SD card.
/// These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53,
/// is not used to select either the W5x00 or the SD card, but it must be kept as an output
/// or the SPI interface won't work.
/// See https://www.arduino.cc/en/Main/ArduinoEthernetShieldV1 for details on the W5x00 Sield
///
///
//*****************************************************************************
#include <SmartThingsEthernetW5x00.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
// "RESERVED" pins for W5x00 Ethernet Shield - best to avoid
#define PIN_4_RESERVED 4 //reserved by W5x00 Shield on both UNO and MEGA
#define PIN_1O_RESERVED 10 //reserved by W5x00 Shield on both UNO and MEGA
#define PIN_11_RESERVED 11 //reserved by W5x00 Shield on UNO
#define PIN_12_RESERVED 12 //reserved by W5x00 Shield on UNO
#define PIN_13_RESERVED 13 //reserved by W5x00 Shield on UNO
#define PIN_50_RESERVED 50 //reserved by W5x00 Shield on MEGA
#define PIN_51_RESERVED 51 //reserved by W5x00 Shield on MEGA
#define PIN_52_RESERVED 52 //reserved by W5x00 Shield on MEGA
#define PIN_53_RESERVED 53 //reserved by W5x00 Shield on MEGA
#define PIN_LED 13 //Onboard LED
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//W5x00 Ethernet Shield Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
byte mac[] = {0x06,0x02,0x03,0x04,0x05,0x06}; //MAC address, leave first octet 0x06, change others to be unique // <---You must edit this line!
IPAddress ip(192, 168, 1, 204); //Arduino device IP Address // <---You must edit this line!
IPAddress gateway(192, 168, 1, 1); //router gateway // <---You must edit this line!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1); //DNS server // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Smartthings hub information
IPAddress hubIp(192,168,1,149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
//Create a SmartThings Ethernet W5x00 object
st::SmartThingsEthernetW5x00 smartthing(mac, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
bool isDebugEnabled; // enable or disable debug in this example
int stateLED; // state to track last set value of LED
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
stateLED = 1; // save state as 1 (on)
digitalWrite(PIN_LED, HIGH); // turn LED on
smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
stateLED = 0; // set state to 0 (off)
digitalWrite(PIN_LED, LOW); // turn LED off
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
stateLED = 0; // matches state of hardware pin set below
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, LOW); // set value to LOW (off) to match stateLED=0
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("setup.."); // print out 'setup..' on start
}
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

View File

@@ -0,0 +1,147 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings ThingShield On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2017-02-10 to work with new "SmartThings v2.0" Library
/// -Now supports automatic selectic of SoftwareSerial or HardwareSerial constructor
/// depending on the Arduino Model.
/// -If using an Arduino UNO R3, be sure to set the ThingShield switch to the D2/D3 position
/// -If using an Arduino Leonardo, be sure to set the ThingShield switch to the D0/D1 position
/// -If using an Arduino MEGA 2560, bbe sure to set the ThingShield switch to the D2/D3 position AND
/// connect jumper wires between pins 2 & 14 as well as between pins 3 & 15.
///
/// DO NOT USE PINS 0,1,2,3,6 for I/O in your sketch as pins 0,1,2,3 are used by the ThingShield
/// and USB communications to your computer. Pin 6 is reserved by the ThingShield.
///
/// @note UNO R3 Pins
/// ______________
/// | |
/// | SW[] |
/// |[]RST |
/// | AREF |--
/// | GND |--
/// | 13 |--X Onboard LED
/// | 12 |--
/// | 11 |--
/// --| 3.3V 10 |--
/// --| 5V 9 |--
/// --| GND 8 |--
/// --| GND |
/// --| Vin 7 |--
/// | 6 |--Reserved
/// --| A0 5 |--
/// --| A1 ( ) 4 |--
/// --| A2 3 |--X THING_RX
/// --| A3 ____ 2 |--X THING_TX
/// --| A4 | | 1 |--X THING_RX
/// --| A5 | | 0 |--X THING_RX
/// |____| |____|
/// |____|
///
//*****************************************************************************
#include <SmartThingsThingShield.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
#define PIN_LED 13
#define PIN_THING_RX 3
#define PIN_THING_TX 2
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) //Arduino UNO, NANO, MINI
st::SmartThingsThingShield smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); //Use Software Serial constructor
#elif defined(ARDUINO_AVR_LEONARDO) //Arduino Leonardo
st::SmartThingsThingShield smartthing(&Serial1, messageCallout); //Use Hardware Serial constructor w/Serial1
#elif defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) //Arduino MEGA 1280 or 2560
st::SmartThingsThingShield smartthing(&Serial3, messageCallout); //Use Hardware Serial constructor w/Serial3
#else
//assume user is using an UNO for the unknown case
st::SmartThingsThingShield smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); //Use Software Serial constructor
#endif
bool isDebugEnabled; // enable or disable debug in this example
int stateLED; // state to track last set value of LED
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
stateLED = 1; // save state as 1 (on)
digitalWrite(PIN_LED, HIGH); // turn LED on
smartthing.shieldSetLED(0, 0, 1);
smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
stateLED = 0; // set state to 0 (off)
digitalWrite(PIN_LED, LOW); // turn LED off
smartthing.shieldSetLED(0, 0, 0);
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
stateLED = 0; // matches state of hardware pin set below
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, LOW); // set value to LOW (off) to match stateLED=0
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("setup.."); // print out 'setup..' on start
}
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

View File

@@ -0,0 +1,132 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Ethernet WiFiEsp On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2017-02-20 to work with new "SmartThings v2.0" Library
///
/// Notes: The Arduino MEGA 2560 communicates via Serial1 to the ESP-01 WiFi board
/// to your home network router, then to the ST Hub, and eventually to the
/// ST cloud servers.
///
/// You must connect the ESP-01 to the Arduino MEGA 2560's "Serial1"
/// Hardware Serial port on pins 18 & 19. Google it!
///
/// The ESP-01 must be running a version of firmware compatible with
/// the WiFiEsp library. Try the examples in the WiFiEsp library
/// to make sure everything is wried correctly before trying this sketch!
///
//*****************************************************************************
#include <SmartThingsWiFiEsp.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
#define PIN_LED 13
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//ESP8266 WiFi Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid = "yourSSIDhere"; // <---You must edit this line!
String str_password = "yourWiFiPasswordhere"; // <---You must edit this line!
IPAddress ip(192, 168, 1, 203); // Device IP Address // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
//Create a SmartThings Ethernet ESP8266WiFi object using the Arduino + ESP-01 constructor
st::SmartThingsWiFiEsp smartthing(&Serial1, str_ssid, str_password, ip, serverPort, hubIp, hubPort, messageCallout);
bool isDebugEnabled; // enable or disable debug in this example
int stateLED; // state to track last set value of LED
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
stateLED = 1; // save state as 1 (on)
digitalWrite(PIN_LED, HIGH); // turn LED on
//smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
stateLED = 0; // set state to 0 (off)
digitalWrite(PIN_LED, LOW); // turn LED off
//smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
stateLED = 0; // matches state of hardware pin set below
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("");
Serial.println("setup.."); // print out 'setup..' on start
}
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, LOW); // set value to LOW (off) to match stateLED=0
// initialize Hardware Serial UART for ESP module
Serial1.begin(115200); //May need to adjust the baud rate for your ESP-01 (9600, 57600, 115200)
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

View File

@@ -0,0 +1,129 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Ethernet WiFi NINA On/Off with LED Example
///
/// Revised by Dan Ogorchock on 2020-01-19 to work with new "SmartThings v2.0" Library
///
/// Notes: The Arduino with NINA communicates via WiFi to your home network router,
/// then to the ST Hub, and eventually to the ST cloud servers.
///
///
//*****************************************************************************
#include <SmartThingsWiFiNINA.h>
//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//WiFiNINA Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid = "yourSSIDhere"; // <---You must edit this line!
String str_password = "yourWiFiPasswordhere"; // <---You must edit this line!
IPAddress ip(192, 168, 1, 202); // Device IP Address // <---You must edit this line if using static IP!
IPAddress gateway(192, 168, 1, 1); //router gateway // <---You must edit this line if using static IP!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line if using static IP!
IPAddress dnsserver(192, 168, 1, 1); //DNS server // <---You must edit this line if using static IP!
const unsigned int serverPort = 8090; // port to run the http server on
// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
//IPAddress hubIp(192, 168, 1, 149); // Hubitat hub ip // <---You must edit this line!
//const unsigned int hubPort = 39501; // Hubitat hub port
//Create a SmartThings Ethernet WiFiNINA object (comment/uncomment the lines below as desired - only ONE can be active)
// static IP
st::SmartThingsWiFiNINA smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
// DHCP
//st::SmartThingsWiFiNINA smartthing(str_ssid, str_password, serverPort, hubIp, hubPort, messageCallout);
bool isDebugEnabled; // enable or disable debug in this example
//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
digitalWrite(PIN_LED, LOW); // turn LED on
smartthing.send("on"); // send message to cloud
}
//*****************************************************************************
void off()
{
digitalWrite(PIN_LED, HIGH); // turn LED off
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("");
Serial.println("setup.."); // print out 'setup..' on start
}
// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, HIGH); // set value to HIGH (off)
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
smartthing.init();
//synch up the ST cloud
smartthing.send("off"); // send message to cloud
}
//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
}
//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}