forked from switchdoclabs/OurWeatherWeatherPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDL_ESP8266_WeatherPlus.ino
2407 lines (1585 loc) · 53.3 KB
/
SDL_ESP8266_WeatherPlus.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Filename WeatherPlus.ino
// Version 036 August 2019
// SwitchDoc Labs, LLC
//
//
//
#define WEATHERPLUSESP8266VERSION "036"
#define WEATHERPLUSPUBNUBPROTOCOL "OURWEATHER036"
// define DEBUGPRINT to print out lots of debugging information for WeatherPlus.
#undef DEBUGPRINT
#undef PUBNUB_DEBUG
#undef DEBUGBLYNK
#define BLYNK_NO_BUILTIN
#define BLYNK_PRINT Serial // Defines the object that is used for printing
#undef BLYNK_DEBUG
#define BLYNK_USE_128_VPINS
#include <BlynkSimpleEsp8266.h>
// Change this to undef if you don't have the OLED present
#define OLED_Present
// BOF preprocessor bug prevent - insert on top of your arduino-code
#if 1
__asm volatile ("nop");
#endif
// Board options
#pragma GCC diagnostic ignored "-Wwrite-strings"
extern "C" {
#include "user_interface.h"
}
//#include "Time/TimeLib.h"
#include "TimeLib.h"
bool WiFiPresent = false;
#include <ESP8266WiFi.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include "WiFiManager.h" //https://github.com/tzapu/WiFiManager
//gets called when WiFiManager enters configuration mode
//void configModeCallback (WiFiManager *myWiFiManager)
void configModeCallback ()
{
Serial.println("Entered config mode");
Serial.println(WiFi.softAPIP());
}
// OTA updated
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <EEPROM.h>
#include "config.h"
int pubNubEnabled;
String SDL2PubNubCode = "";
String SDL2PubNubCode_Sub = "";
// Blynk Codes
String BlynkAuthCode = "";
bool UseBlynk = false;
BlynkTimer Btimer;
// Attach virtual serial terminal to Virtual Pin
WidgetTerminal statusTerminal(V32);
#define PUBLISHINTERVALSECONDS 30
#define PubNub_BASE_CLIENT WiFiClient
#define PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP
#include "PubNub.h"
// parsing function
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {
0, -1
};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
//
char channel1[] = "OWIOT1";
char uuid[] = WEATHERPLUSPUBNUBPROTOCOL;
#include <Wire.h>
#include <Arduino.h> //needed for Serial.println
// debug the REST library
#define DEBUG_MODE 1
#include "MaREST.h"
#include <String.h>
// display modes
#define DISPLAY_POWERUP 0
#define DISPLAY_IPDISPLAY 1
#define DISPLAY_WEATHER_SMALL 2
#define DISPLAY_WEATHER_MEDIUM 3
#define DISPLAY_WEATHER_LARGE 4
#define DISPLAY_STATUS 5
#define DISPLAY_ACCESSPOINT 6
#define DISPLAY_WEATHER_DEMO 7
#define DISPLAY_TRYING_AP 8
#define DISPLAY_FAILING_AP 9
#define DISPLAY_DATETIME 10
#define DISPLAY_UPDATING 11
#define DISPLAY_NO_UPDATE_AVAILABLE 12
#define DISPLAY_NO_UPDATE_FAILED 13
#define DISPLAY_UPDATE_FINISHED 14
#define DISPLAY_SUNAIRPLUS 16
#define DISPLAY_WXLINK 17
#define DISPLAY_SDL2PUBNUBCODE 18
#define DISPLAY_FAILED_RECONNECT 19
#define DISPLAY_LIGHTNING_STATUS 20
#define DISPLAY_LIGHTNING_DISPLAY 21
#define DEBUG
// Rest Interface
#define PREFIX ""
String RestTimeStamp;
String RestDataString;
String Version;
//----------------------------------------------------------------------
//Local WiFi
int WiFiSetupFlag = 0;
String APssid;
String Wssid;
String WPassword;
WiFiServer server(WEB_SERVER_PORT);
IPAddress myConnectedIp;
IPAddress myConnectedGateWay;
IPAddress myConnectedMask;
//----------------------------------------------------------------------
int blinkPin = 0; // pin to blink led at each reading
// Create an instance of the server
// Create aREST instance
aREST rest = aREST();
// commands are functions that get called by the webserver framework
// they can read any posted data from client, and they output to server
#include "elapsedMillis.h"
elapsedMillis timeElapsed; //declare global if you don't want it reset every time loop
elapsedMillis timeElapsed300Seconds; //declare global if you don't want it reset every time loop
// BMP180 / BMP280 Sensor
// Both are stored in BMP180 variables
//
#include "MAdafruit_BMP280.h"
#include "MAdafruit_BMP085.h"
Adafruit_BMP280 bme;
Adafruit_BMP085 bmp;
#define SENSORS_PRESSURE_SEALEVELHPA 1015.00
float altitude_meters;
float BMP180_Temperature;
float BMP180_Pressure;
float BMP180_Altitude;
bool BMP180Found;
bool BMP280Found;
int EnglishOrMetric; // 0 = English units, 1 = Metric
int WeatherDisplayMode;
// DS3231 Library functions
#include "RtcDS3231.h"
RtcDS3231 Rtc;
// AM2315
float AM2315_Temperature;
float AM2315_Humidity;
float dewpoint;
bool AM2315_Present = false;
#include "SDL_ESP8266_HR_AM2315.h"
SDL_ESP8266_HR_AM2315 am2315;
float dataAM2315[2]; //Array to hold data returned by sensor. [0,1] => [Humidity, Temperature]
boolean AOK; // 1=successful read
// SHT30
#include "WEMOS_SHT3X.h"
SHT3X sht30(0x44);
bool SHT30_Present = false;
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
#include "AS3935.h"
// ThunderBoard AS3935 from SwitchDoc Labs
AS3935 as3935(0x02, 3);
// lightning state variables as3935
String as3935_LastLightning = "";
int as3935_LastLightningDistance = 0;
String as3935_LastEvent = "";
int as3935_LastReturnIRQ = 0;
String as3935_LastLightningTimeStamp = "";
String as3935_LastEventTimeStamp = "";
int as3835_LightningCountSinceBootup = 0;
String as3935_FullString = "";
String as3935_Params = "";
int as3935_NoiseFloor = 2;
bool as3935_Indoor = true;
int as3935_TuneCap = 7;
bool as3935_DisturberDetection = false;
int as3935_WatchdogThreshold = 3;
int as3935_SpikeDetection = 3;
bool AS3935Present = false;
void printAS3935Registers()
{
int noiseFloor = as3935.getNoiseFloor();
int spikeRejection = as3935.getSpikeRejection();
int watchdogThreshold = as3935.getWatchdogThreshold();
Serial.print("Noise floor is: ");
Serial.println(noiseFloor, DEC);
Serial.print("Spike rejection is: ");
Serial.println(spikeRejection, DEC);
Serial.print("Watchdog threshold is: ");
Serial.println(watchdogThreshold, DEC);
}
int parseOutAS3935Parameters()
{
// check for bad string
if (as3935_Params.indexOf(",") == -1)
as3935_Params = "2,1,7,0,3,3";
String Value;
Value = getValue(as3935_Params, ',', 0);
if ((Value.toInt() < 0) || (Value.toInt() > 7))
return 2;
Value = getValue(as3935_Params, ',', 1);
if ((Value.toInt() < 0) || (Value.toInt() > 1))
return 2;
Value = getValue(as3935_Params, ',', 2);
if ((Value.toInt() < 0) || (Value.toInt() > 15))
return 2;
Value = getValue(as3935_Params, ',', 3);
if ((Value.toInt() < 0) || (Value.toInt() > 1))
return 2;
Value = getValue(as3935_Params, ',', 4);
if ((Value.toInt() < 0) || (Value.toInt() > 15))
return 2;
Value = getValue(as3935_Params, ',', 5);
if ((Value.toInt() < 0) || (Value.toInt() > 15))
return 2;
// OK, if we are here then all data is good
Value = getValue(as3935_Params, ',', 0);
as3935_NoiseFloor = Value.toInt();
Value = getValue(as3935_Params, ',', 1);
as3935_Indoor = Value.toInt();
Value = getValue(as3935_Params, ',', 2);
as3935_TuneCap = Value.toInt();
Value = getValue(as3935_Params, ',', 3);
as3935_DisturberDetection = Value.toInt();
Value = getValue(as3935_Params, ',', 4);
as3935_WatchdogThreshold = Value.toInt();
Value = getValue(as3935_Params, ',', 5);
as3935_SpikeDetection = Value.toInt();
return 1;
}
void setAS3935Parameters()
{
as3935.setTuningCapacitor(as3935_TuneCap); // set to 1/2 - middle - you can calibrate on an Arduino UNO and use the value from there (pf/8)
// lightning state variables as3935
// first let's turn on disturber indication and print some register values from AS3935
// tell AS3935 we are indoors, for outdoors use setOutdoors() function
if (as3935_Indoor == true)
{
as3935.setIndoor();
}
else
{
as3935.setOutdoor();
}
as3935.setNoiseFloor(as3935_NoiseFloor);
#ifdef DEBUGPRINT
Serial.print("NoiseFloor=");
Serial.println(as3935_NoiseFloor);
#endif
//AS3935.calibrate(); // can't calibrate because IRQ is polled and not through an Interrupt line on ESP8266
// turn on indication of distrubers, once you have AS3935 all tuned, you can turn those off with disableDisturbers()
if (as3935_DisturberDetection == true)
{
as3935.enableDisturbers();
}
else
{
as3935.disableDisturbers();
}
uint16_t getWatchdogThreshold(void);
uint16_t setWatchdogThreshold(uint16_t wdth);
as3935.setSpikeRejection(as3935_SpikeDetection);
as3935.setWatchdogThreshold(as3935_WatchdogThreshold);
// end set parameters
// set up as3935 REST variable
as3935_Params = String(as3935_NoiseFloor) + ",";
as3935_Params += String(as3935_Indoor) + ",";
as3935_Params += String(as3935_TuneCap) + ",";
as3935_Params += String(as3935_DisturberDetection) + ",";
as3935_Params += String(as3935_WatchdogThreshold) + ",";
as3935_Params += String(as3935_SpikeDetection) ;
printAS3935Registers();
}
// Station Name
String stationName;
String adminPassword;
// Health Indications for WeatherPlus
int heapSize;
// WeatherUnderground
String WeatherUnderground_StationID;
String WeatherUnderground_StationKey;
int lastMessageID;
// WeatherRack
float windSpeedMin;
float windSpeedMax;
float windGustMin;
float windGustMax;
float windDirectionMin;
float windDirectionMax;
float currentWindSpeed;
float currentWindGust;
float currentWindDirection;
float rainTotal;
float rainCalendarDay;
int lastDay;
float startOfDayRain;
#include "SDL_RasPiGraphLibrary.h"
// setup the RasPiConnect Graph Arrays
SDL_RasPiGraphLibrary windSpeedGraph(10, SDL_MODE_LABELS);
SDL_RasPiGraphLibrary windGustGraph(10, SDL_MODE_LABELS);
SDL_RasPiGraphLibrary windDirectionGraph(10, SDL_MODE_LABELS);
char windSpeedBuffer[150]; // wind speed graph
char windGustBuffer[150]; // wind speed graph
char windDirectionBuffer[150]; // wind speed graph
// WeatherRack
// LED connected to digital GPIO 0
int WpinLED = 0;
// Anenometer connected to GPIO 14
int pinAnem = 14;
// Rain Bucket connected to GPIO 12
int pinRain = 12;
#include "OWMAdafruit_ADS1015.h"
Adafruit_ADS1015 ads1015(0x49);
int current_quality = -1;
Adafruit_ADS1115 adsAirQuality(0x48);
long currentAirQuality;
long currentAirQualitySensor;
int INTcurrentAirQualitySensor;
bool AirQualityPresent = false;
#include "AirQualitySensor.h"
#include "SDL_Weather_80422.h"
//SDL_Weather_80422 weatherStation(pinAnem, pinRain, 0, 0, A0, SDL_MODE_INTERNAL_AD );
SDL_Weather_80422 weatherStation(pinAnem, pinRain, 0, 0, A0, SDL_MODE_I2C_ADS1015 );
// SDL_MODE_I2C_ADS1015
//
// RasPiConnect
long messageCount;
static uint8_t mac[] = LOCALMAC;
static uint8_t ip[] = LOCALIP;
// this is our current command object structure. It is only valid inside void jsonCmd
typedef struct {
char ObjectID[40];
char ObjectFlags[40];
char ObjectAction[40];
char ObjectName[40];
char ObjectServerID[40];
char Password[40];
char ObjectType[40];
char Validate[40];
} currentObjectStructure;
char *md5str;
char ST1Text[40]; // used in ST-1 Send text control
char bubbleStatus[40]; // What to send to the Bubble status
#include "RainFunctions.h"
float lastRain;
#include "WeatherUnderground.h"
#include "Utils.h"
// OLED Constants
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
// aREST functions
#include "aRestFunctions.h"
#include "SDL2PubNub.h"
// SunAirPlus
bool SunAirPlus_Present;
float BatteryVoltage;
float BatteryCurrent;
float LoadVoltage;
float LoadCurrent;
float SolarPanelVoltage;
float SolarPanelCurrent;
// WXLink Support
#include "Crc16.h"
//Crc 16 library (XModem)
Crc16 crc;
bool WXLink_Present;
float WXBatteryVoltage;
float WXBatteryCurrent;
float WXLoadCurrent;
float WXSolarPanelVoltage;
float WXSolarPanelCurrent;
long WXMessageID;
bool WXLastMessageGood;
#include "WXLink.h"
#include "SDL_Arduino_INA3221.h"
SDL_Arduino_INA3221 SunAirPlus;
// the three channels of the INA3221 named for SunAirPlus Solar Power Controller channels (www.switchdoc.com)
#define LIPO_BATTERY_CHANNEL 1
#define SOLAR_CELL_CHANNEL 2
#define OUTPUT_CHANNEL 3
// OLED Display
#include "OWMAdafruit_GFX.h"
#include "ESP_SSD1306.h"
#define min(a,b) ((a)<(b)?(a):(b))
#define OLED_RESET 4
ESP_SSD1306 display(OLED_RESET);
#include "OLEDDisplay.h"
//
//
//
//
// validate temperature from AM2315 - Fixes the rare +16 degrees C issue
bool invalidTemperatureFound;
float validateTemperature(float incomingTemperature)
{
if (incomingTemperature > AM2315_Temperature + 15.0) // check for large jump in temperature
{
// OK, we may have an invalid temperature. Make sure this is not a startup (current humidity will be 0.0 if startup)
if (AM2315_Humidity < 0.1)
{
// we are in startup phase, so accept temperature
invalidTemperatureFound = false;
return incomingTemperature;
}
else
{
// we have an issue with a bad read (typically a +32 degrees C increase)
// so send last good temperature back and flag a bad temperature
invalidTemperatureFound = true;
return AM2315_Temperature;
}
}
if (incomingTemperature < AM2315_Temperature - 15.0) // check for large decrease in temperature
{
// OK, we may have an invalid temperature. Make sure this is not a startup (current humidity will be 0.0 if startup)
if (AM2315_Humidity < 0.1)
{
// we are in startup phase, so accept temperature
invalidTemperatureFound = false;
return incomingTemperature;
}
else
{
// we have an issue with a bad read (typically a +32 degrees C increase)
// so send last good temperature back and flag a bad temperature
invalidTemperatureFound = true;
return AM2315_Temperature;
}
}
invalidTemperatureFound = false;
return incomingTemperature; // good temperature
}
//scan for I2C Addresses
bool scanAddressForI2CBus(byte from_addr)
{
byte error;
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(from_addr);
error = Wire.endTransmission();
if (error == 0)
{
return true;
}
else if (error == 4)
{
}
return false;
}
RtcDateTime lastBoot;
#include "BlynkRoutines.h"
void setup() {
invalidTemperatureFound = false;
// WiFi reset loop fix - erase the WiFi saved area
WiFi.persistent(false);
BMP180Found = false;
BMP280Found = false;
stationName = "";
WeatherUnderground_StationID = "XXXX";
WeatherUnderground_StationKey = "YYYY";
adminPassword = "admin";
altitude_meters = 637.0; // default to 611
pinMode(blinkPin, OUTPUT); // pin that will blink every reading
digitalWrite(blinkPin, HIGH); // High of this pin is LED OFF
Serial.begin(115200); // set up Serial library at 9600 bps
// Setup DS3231 RTC
//--------RTC SETUP ------------
Rtc.Begin();
#if defined(ESP8266)
Wire.begin(5, 4);
#endif
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
Serial.println("--------");
printDateTime(compiled);
Serial.println("--------");
Serial.println();
if (!Rtc.IsDateTimeValid())
{
// Common Cuases:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
// following line sets the RTC to the date & time this sketch was compiled
// it will also reset the valid flag internally unless the Rtc device is
// having an issue
Rtc.SetDateTime(compiled);
}
RtcDateTime now = Rtc.GetDateTime();
lastBoot = now;
rainCalendarDay = 0.0;
startOfDayRain = 0.0;
lastDay = now.Day();
String currentTimeString;
currentTimeString = returnDateTime(now);
Serial.print("now fromRTC =");
Serial.println(currentTimeString);
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
// never assume the Rtc was last configured by you, so
// just clear them to your needed state
Rtc.Enable32kHzPin(false);
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
EEPROM.begin(512);
#ifdef OLED_Present
OLEDDisplaySetup();
updateDisplay(DISPLAY_POWERUP);
#endif
delay(2000);
if (digitalRead(0) == 0)
{
Serial.println("GPIO0 button down - Invalidating EEPROM");
invalidateEEPROMState();
}
readEEPROMState();
// now set up thunderboard AS3935
// reset all internal register values to defaults
as3935.reset();
int noiseFloor = as3935.getNoiseFloor();
Serial.print("noiseFloor=");
Serial.println(noiseFloor);
if (noiseFloor == 2)
{
Serial.println("AS3935 Present");
AS3935Present = true;
}
else
{
Serial.println("AS3935 Not Present");
AS3935Present = false;
}
if (AS3935Present == true)
{
parseOutAS3935Parameters();
setAS3935Parameters();
}
// Set up Wifi
const char APpassphrase[] = "OurWeather";
// Append the last two bytes of the MAC (HEX'd) to string to make unique
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
macID.toUpperCase();
APssid = "OurWeather - " + macID;
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
wifiManager.setDebugOutput(true);
//reset saved settings
//wifiManager.resetSettings();
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
wifiManager.setTimeout(600);
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect(APssid.c_str())) {
Serial.println("failed to connect and hit timeout");
blinkLED(4, 300); // blink 4, failed to connect
//reset and try again, or maybe put it to deep sleep
//ESP.reset();
//delay(1000);
}
if (WiFi.status() == WL_CONNECTED)
WiFiPresent = true;
writeEEPROMState();
Serial.print("WiFi Channel= ");
Serial.println(WiFi.channel());
blinkLED(2, 300); // blink twice - OK!
heapSize = ESP.getFreeHeap();
RestTimeStamp = "";
RestDataString = "";
Version = WEATHERPLUSESP8266VERSION;
server.begin();
rest.variable("OurWeatherTime", &RestTimeStamp);
rest.variable("FullDataString", &RestDataString);
rest.variable("FirmwareVersion", &Version);
rest.variable("IndoorTemperature", &BMP180_Temperature);
rest.variable("BarometricPressure", &BMP180_Pressure);
rest.variable("Altitude", &BMP180_Altitude);
rest.variable("OutdoorTemperature", &AM2315_Temperature);
rest.variable("OutdoorHumidity", &AM2315_Humidity);
rest.variable("CurrentWindSpeed", ¤tWindSpeed);
rest.variable("CurrentWindGust", ¤tWindGust);
rest.variable("CurrentWindDirection", ¤tWindDirection);
rest.variable("EnglishOrMetric", &EnglishOrMetric);
rest.variable("RainTotal", &rainTotal);
rest.variable("WindSpeedMin", &windSpeedMin);
rest.variable("WindSpeedMax", &windSpeedMax);
rest.variable("WindGustMin", &windGustMin);
rest.variable("WindGustMax", &windGustMax);
rest.variable("WindDirectionMin", &windDirectionMin);
rest.variable("WindDirectionMax", &windDirectionMax);
rest.variable("AirQualitySensor", &INTcurrentAirQualitySensor);
// as3935 rest variables