-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSousVideLogger.ino
113 lines (101 loc) · 3.47 KB
/
SousVideLogger.ino
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
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
// Connections for LCD need to be as follows:
// LiquidCrystal lcd(rs, rw, E, d4, d5, d6, d7);
LiquidCrystal lcd(2, 0, 4, 5, 12, 14, 16);
//Define pin used for temp probes
#define ONE_WIRE_BUS 13
// Setup a oneWire instance to communicate with D18S20's
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
// Variable defs
int timeout = 0;
int deviceCount = 0;
float temperature;
float mytemps[4];
//Wifi information use to connect to wifi
char* ssid = "Wifiname";
const char* password = "passphrase";
//Information host to recieve data
const uint16_t port = 8090; //Port socket is listening on
const char * host = "192.168.1.1"; //ip address socket is listening on.
void setup()
{
Serial.begin(9600);
lcd.begin(20,4); // Setup size of LCD
lcd.clear(); // start with a blank screen
sensors.begin(); // Start up the sensor library
lcd.setCursor(0,0); //Set cusor to position 0 first line of display
lcd.print("Locating devices..."); //write text on first line of display
lcd.setCursor(0,1);
lcd.print("Found ");
deviceCount = sensors.getDeviceCount(); // locate devices on the bus and return number of devices
lcd.print(deviceCount);
lcd.print(" devices.");
lcd.setCursor(0,3);
lcd.print("Sleeping ");
lcd.print("3 ");
delay(1000);
lcd.print("2 ");
delay(1000);
lcd.print("1 ");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Trying to connect to");
lcd.setCursor(0,1);
lcd.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED and timeout < 20) {
delay(500);
lcd.println("..");
timeout = timeout + 1;
}
lcd.clear();
if ( timeout >= 20) { //if connection to wifi have not been made within the time print information.
lcd.setCursor(0,0);
lcd.print("Failed to connect to wifi");
lcd.setCursor(0,1);
lcd.print("Data will not not be send");
delay(2000);
}
}
void loop()
{
WiFiClient client;
while (true) {
sensors.requestTemperatures();
// Display temperature from each sensor by looping over the number of sensors previously obtained.
// By using the index to select the line in the display the sensors are printed on individual lines in the LCD
for (int i = 0; i < deviceCount; i++) {
lcd.setCursor(0,i);
lcd.print("Sensor ");
lcd.print(i+1);
lcd.print(" : ");
temperature = sensors.getTempCByIndex(i);
lcd.print(temperature);
lcd.print((char)223);//shows degrees symbol
lcd.print("C ");
mytemps[i] = temperature; //write temperature to array to alway to a fixed length array to the server
}
if (timeout < 20) { //only send data if wifi connection didn't timeout during setup
if (!client.connected()) { //if connection to socket server no established, establish it
client.connect(host, port);
}
if (!client.connected()) { //if not connection don't sendt data
lcd.print("!"); //indicate data is NOT send by ! mark in buttom right coner
}
else { //If connection established send data to socket
client.println("###");
for(int i = 0; i < 4; i++) {
client.println(mytemps[i]);
}
lcd.print("#"); //indicate data IS send by ! mark in buttom right coner
}
}
delay(1000); //refresh rate
}
}