Skip to content

Commit 00a8294

Browse files
committed
Added example for WiFiNINA (new Arduinos)
1 parent 4dfec98 commit 00a8294

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//*****************************************************************************
2+
/// @file
3+
/// @brief
4+
/// Arduino SmartThings Ethernet WiFi NINA On/Off with LED Example
5+
///
6+
/// Revised by Dan Ogorchock on 2020-01-19 to work with new "SmartThings v2.0" Library
7+
///
8+
/// Notes: The Arduino with NINA communicates via WiFi to your home network router,
9+
/// then to the ST Hub, and eventually to the ST cloud servers.
10+
///
11+
///
12+
//*****************************************************************************
13+
14+
#include <SmartThingsWiFiNINA.h>
15+
16+
//*****************************************************************************
17+
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
18+
// 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
19+
//*****************************************************************************
20+
21+
//*****************************************************************************
22+
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
23+
// 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
24+
//*****************************************************************************
25+
SmartThingsCallout_t messageCallout; // call out function forward decalaration
26+
27+
//******************************************************************************************
28+
//WiFiNINA Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
29+
//******************************************************************************************
30+
String str_ssid = "yourSSIDhere"; // <---You must edit this line!
31+
String str_password = "yourWiFiPasswordhere"; // <---You must edit this line!
32+
IPAddress ip(192, 168, 1, 202); // Device IP Address // <---You must edit this line if using static IP!
33+
IPAddress gateway(192, 168, 1, 1); //router gateway // <---You must edit this line if using static IP!
34+
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line if using static IP!
35+
IPAddress dnsserver(192, 168, 1, 1); //DNS server // <---You must edit this line if using static IP!
36+
const unsigned int serverPort = 8090; // port to run the http server on
37+
38+
// Smartthings Hub Information
39+
IPAddress hubIp(192, 168, 1, 149); // smartthings hub ip // <---You must edit this line!
40+
const unsigned int hubPort = 39500; // smartthings hub port
41+
42+
// Hubitat Hub Information
43+
//IPAddress hubIp(192, 168, 1, 149); // Hubitat hub ip // <---You must edit this line!
44+
//const unsigned int hubPort = 39501; // Hubitat hub port
45+
46+
47+
48+
//Create a SmartThings Ethernet WiFiNINA object (comment/uncomment the lines below as desired - only ONE can be active)
49+
// static IP
50+
st::SmartThingsWiFiNINA smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
51+
// DHCP
52+
//st::SmartThingsWiFiNINA smartthing(str_ssid, str_password, serverPort, hubIp, hubPort, messageCallout);
53+
54+
bool isDebugEnabled; // enable or disable debug in this example
55+
56+
57+
//*****************************************************************************
58+
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
59+
// 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
60+
//*****************************************************************************
61+
void on()
62+
{
63+
digitalWrite(PIN_LED, LOW); // turn LED on
64+
smartthing.send("on"); // send message to cloud
65+
}
66+
67+
//*****************************************************************************
68+
void off()
69+
{
70+
digitalWrite(PIN_LED, HIGH); // turn LED off
71+
smartthing.send("off"); // send message to cloud
72+
}
73+
74+
//*****************************************************************************
75+
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
76+
// 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
77+
//*****************************************************************************
78+
void setup()
79+
{
80+
// setup default state of global variables
81+
isDebugEnabled = true;
82+
83+
if (isDebugEnabled)
84+
{ // setup debug serial port
85+
Serial.begin(9600); // setup serial with a baud rate of 9600
86+
Serial.println("");
87+
Serial.println("setup.."); // print out 'setup..' on start
88+
}
89+
90+
// setup hardware pins
91+
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
92+
digitalWrite(PIN_LED, HIGH); // set value to HIGH (off)
93+
94+
//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
95+
smartthing.init();
96+
97+
//synch up the ST cloud
98+
smartthing.send("off"); // send message to cloud
99+
}
100+
101+
//*****************************************************************************
102+
void loop()
103+
{
104+
// run smartthing logic
105+
smartthing.run();
106+
}
107+
108+
//*****************************************************************************
109+
void messageCallout(String message)
110+
{
111+
// if debug is enabled print out the received message
112+
if (isDebugEnabled)
113+
{
114+
Serial.print("Received message: '");
115+
Serial.print(message);
116+
Serial.println("' ");
117+
}
118+
119+
// if message contents equals to 'on' then call on() function
120+
// else if message contents equals to 'off' then call off() function
121+
if (message.equals("on"))
122+
{
123+
on();
124+
}
125+
else if (message.equals("off"))
126+
{
127+
off();
128+
}
129+
}

Arduino/libraries/SmartThings/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SmartThingsESP8266WiFi KEYWORD1
1010
SmartThingsESP32WiFi KEYWORD1
1111
SmartThingsWiFiEsp KEYWORD1
1212
SmartThingsWiFi101 KEYWORD1
13+
SmartThingsWiFiNINA KEYWORD1
1314
SmartThingsCallout_t KEYWORD1
1415
SmartThingsNetworkState_t KEYWORD1
1516

0 commit comments

Comments
 (0)