-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduinoMainMod
More file actions
117 lines (83 loc) · 2.75 KB
/
ArduinoMainMod
File metadata and controls
117 lines (83 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Please use an Arduino IDE 1.6.8 or greater
#include "iot_configs.h"
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include <AzureIoTHub.h>
#if defined(IOT_CONFIG_MQTT)
#include <AzureIoTProtocol_MQTT.h>
#elif defined(IOT_CONFIG_HTTP)
#include <AzureIoTProtocol_HTTP.h>
#endif
#include "remote_monitoring.h"
static char ssid[] = IOT_CONFIG_WIFI_SSID;
static char pass[] = IOT_CONFIG_WIFI_PASSWORD;
char incomingByte = 'a';
void setup() {
initSerial();
initWifi();
initTime();
pinMode(15, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
interrupts();
}
void loop() {
// Run the Remote Monitoring from the Azure IoT Hub C SDK
// You must set the device id, device key, IoT Hub name and IotHub suffix in
// remote_monitoring.c
remote_monitoring_run();
}
void initSerial() {
// Start serial and initialize stdout
Serial.begin(115200);
Serial.setDebugOutput(true);
}
void initWifi() {
// Attempt to connect to Wifi network:
Serial.print("\r\n\r\nAttempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\r\nConnected to wifi");
}
void initTime() {
time_t epochTime;
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
while (true) {
epochTime = time(NULL);
if (epochTime == 0) {
Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry.");
delay(2000);
} else {
Serial.print("Fetched NTP epoch time is: ");
Serial.println(epochTime);
break;
}
}
}
void serialEvent() {
while (Serial.available()) {
Serial.println("Reding serial event");
// read the incoming byte:
incomingByte = Serial.read();
Serial.println("Reding serial");
if (incomingByte=='r'){
Serial.println("Error");
digitalWrite(15, HIGH);
digitalWrite(13, LOW);
}
if (incomingByte=='g'){
Serial.println("todo bien");
digitalWrite(13, HIGH);
digitalWrite(15, LOW);
}
}
}