1
2#define BLYNK_PRINT Serial
3#include <math.h>
4#include <SPI.h>
5#include <WiFi101.h>
6#include <BlynkSimpleMKR1000.h>
7#include <Arduino_MKRENV.h>
8
9
10char auth[] = "*****";
11char ssid[] = "*****";
12char pass[] = "*****";
13
14
15BlynkTimer timer;
16
17
18
19char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
20 char fmt[20];
21 sprintf(fmt, "%%%d.%df", width, prec);
22 sprintf(sout, fmt, val);
23 return sout;
24}
25
26
27void setup()
28{
29
30 Serial.begin(9600);
31
32 if (!ENV.begin()) {
33 Serial.println("Failed to initialize MKR ENV shield!");
34 while (1);
35 }
36
37
38
39
40 Blynk.begin(auth, ssid, pass);
41
42 timer.setInterval(1000L, sendSensor);
43}
44
45void loop()
46{
47 Blynk.run();
48 timer.run();
49}
50
51
52void sendSensor()
53{
54 float h = ENV.readHumidity();
55 float t = ENV.readTemperature();
56 float lx = ENV.readIlluminance();
57 float p=ENV.readPressure();
58 int uva= ENV.readUVA();
59 int uvb= ENV.readUVB();
60 int uvIndex= ENV.readUVIndex();
61
62 char tt[16];
63 dtostrf(t,1,2,tt);
64char hh[16];
65 dtostrf(h,1,2,hh);
66
67 char lxx[16];
68 dtostrf(lx,1,2,lxx);
69 char pp[16];
70 dtostrf(p,1,2,pp);
71
72
73 if (isnan(h) || isnan(t)) {
74 Serial.println("Error");
75 return;
76 }
77
78 Blynk.virtualWrite(V5, hh);
79 Blynk.virtualWrite(V6, tt);
80 Blynk.virtualWrite(V7, lxx);
81 Blynk.virtualWrite(V8, pp);
82 Blynk.virtualWrite(V9,uva);
83 Blynk.virtualWrite(V10,uvb);
84 Blynk.virtualWrite(V11,uvIndex);
85
86}
87
nedaa22
5 years ago
next step is to make it on local server .. help me with it :)