-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasymesh-sensor-server.ino
111 lines (93 loc) · 2.73 KB
/
easymesh-sensor-server.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
//file to server side to connect the sensor data and send them to the Client side
#include <easyMesh.h>
#include <easyMeshSync.h>
#include <SimpleList.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define MESH_PREFIX "WKI"
#define MESH_PASSWORD "WKI1234"
#define MESH_PORT 5555
Adafruit_BME280 bme; // I2C
const char* ssid = "AndroidAP";
const char* password = "sadbhavna12";
float h, t, p, pin, dp;
char temperatureFString[6];
char dpString[6];
char humidityString[6];
char pressureString[7];
char pressureInchString[6];
uint32_t ID;
String msg,msg1,msg2,msg3,msg4,msgFinal;
String xyz="hello";
// Web Server on port 80
WiFiServer server(80);
easyMesh mesh;
static void (*receivedCallback)( uint32_t ID, String &msg);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(10);
Wire.begin(D3, D4);
Wire.setClock(100000);
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT);
ID=system_get_chip_id();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
mesh.setReceiveCallback(receivedCallback);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Starting the web server
server.begin();
Serial.println("Web server running. Waiting for the ESP IP...");
delay(10000);
// Printing the ESP IP address
Serial.println(WiFi.localIP());
Serial.println(F("BME280 test"));
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void getWeather() {
h = bme.readHumidity();
t = bme.readTemperature();
t = t*1.8+32.0;
dp = t-0.36*(100.0-h);
p = bme.readPressure()/100.0F;
pin = 0.02953*p;
dtostrf(t, 5, 1, temperatureFString);
String msg(temperatureFString);
dtostrf(h, 5, 1, humidityString);
String msg1(humidityString);
dtostrf(p, 6, 1, pressureString);
String msg2(pressureString);
dtostrf(pin, 5, 2, pressureInchString);
String msg3(pressureInchString);
dtostrf(dp, 5, 1, dpString);
String msg4(dpString);
msgFinal=msg+msg1+msg2+msg3+msg4;
delay(100);
}
void loop() {
// put your main code here, to run repeatedly:
getWeather();
mesh.update();
// void receivedCallback( uint32_t ID, String &msg ) ;
void newConnectionCallback( bool adopt );
mesh.sendBroadcast(msgFinal);
if (mesh.sendBroadcast(msgFinal)){
Serial.println("success");
}
delay(100);
mesh.sendBroadcast(xyz);
Serial.println(msgFinal);
}