-
Notifications
You must be signed in to change notification settings - Fork 0
/
diabete.ino
220 lines (152 loc) · 5.14 KB
/
diabete.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
//#include <SoftwareSerial.h>
#include <MySignals.h>
#include "Wire.h"
#include "SPI.h"
//String patientId = 1;
String AP ="Hahaha"; //"wifisba"; "equipeBensliman(SOC)"; "DLink"; // CHANGE ME
String PASS = "tjbl6947"; //"12345678a"; "labri-sba"; "esisba2019";// CHANGE ME
String HOST = "192.168.121.133";
String PORT = "9005";
String year = "year";
String month = "month";
String day = "day";
String hour = "hour";
String minutes = "minutes";
String deviceKey = "BLI3SC1";
String glucose = "glucose";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
float valSensor = 1;
boolean b=true;
void setup() {
Serial.println(deviceKey);
Serial.begin(115200);
MySignals.begin();
bitSet(MySignals.expanderState, EXP_ESP8266_POWER);
MySignals.expanderWrite(MySignals.expanderState);
MySignals.initSensorUART();
MySignals.enableSensorUART(GLUCOMETER);
delay(1000);
MySignals.getGlucose();
MySignals.enableSensorUART(WIFI_ESP8266);
delay(1000);
connectionWifi(AP,PASS);
}
void loop()
{
Serial.begin(115200);
if(b) {
// MySignals.disableMuxUART();
for (uint8_t i = 0; i < MySignals.glucoseLength; i++)
{
Serial.print(F("measure number:"));
Serial.println(i + 1);
Serial.print(F("year:"));
Serial.println(MySignals.glucometerData[i].year);
Serial.print(F("month:"));
Serial.println(MySignals.glucometerData[i].month);
Serial.print(F("day:"));
Serial.println(MySignals.glucometerData[i].day);
Serial.print(F("hour:"));
Serial.println(MySignals.glucometerData[i].hour);
Serial.print(F("minutes:"));
Serial.println(MySignals.glucometerData[i].minutes);
Serial.print(F("glucose:"));
Serial.println(MySignals.glucometerData[i].glucose);
Serial.print(F("meridian:"));
Serial.println(MySignals.glucometerData[i].meridian);
Serial.println();
/*String(patientId),*/
sendDataToMs("BLI3SC1",
String(MySignals.glucometerData[i].year),
String(MySignals.glucometerData[i].month),
String(MySignals.glucometerData[i].day),
String(MySignals.glucometerData[i].hour),
String(MySignals.glucometerData[i].minutes),
String(MySignals.glucometerData[i].glucose));
}
MySignals.enableMuxUART();
b=false;
Serial.println(b);
}
}
void sendDataToMs(String deviceKey, String year, String month, String day, String hour, String minutes, String glucose)
{
/*String patientId,*/
String getData = "GET /iot/patient/add?deviceKey="+deviceKey+"&year=20"+year+"&month="+month+"&day="+day+"&hour="+hour+"&minutes="+minutes+"&glucose="+glucose;
//String getData = "GET /api/add?year=20"+year+"&month="+month+"&day="+day+"&hour="+hour+"&minutes="+minutes+"&glucose="+glucose;
//String getData = "GET /api/add2?glucose="+glucose;
sendCommand("AT+CIPMUX=1",10,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,10,"OK");
sendATcommand("AT+CIPSEND=0,"+String(getData.length()+4),10000,"OK");
Serial.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",10,"OK");
delay(1000);
}
void connectionWifi(String AP,String PASS){
sendCommand("AT",10,"OK");
sendCommand("AT+CWMODE=1",10,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
sendATcommand("AT+CIFSR",10000,"OK");
}
void sendCommand(String command, int maxTime,char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
Serial.println(command);//at+cipsend
if(Serial.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
int8_t sendATcommand(String ATcommand,unsigned int timeout,char* expected_answer1)
{
uint8_t x = 0, answer = 0;
char response[500];
unsigned long previous;
memset(response, '\0', sizeof(response)); // Initialize the string
delay(100);
while ( Serial.available() > 0) Serial.read(); // Clean the input buffer
delay(1000);
Serial.println(ATcommand); // Send the AT command
x = 0;
previous = millis();
// this loop waits for the answer
do
{
if (Serial.available() != 0)
{
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
MySignals.println(response);
}
}
// Waits for the asnwer with time out
}
while ((answer == 0) && ((millis() - previous) < timeout));
return answer;
}