-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSGN_Arduino_Ethernet.cpp
More file actions
144 lines (120 loc) · 2.98 KB
/
SGN_Arduino_Ethernet.cpp
File metadata and controls
144 lines (120 loc) · 2.98 KB
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
#include "SGN_Arduino_Ethernet.h"
dotori::dotori(char *sencode){
senCode = sencode;
}
void dotori::printcode(){
DEBUG_PRINT(senCode);
}
//입력 변수형별 전송 데이터 타입 정리.
void dotori::set(int val){
void * vo = &val;
value = *(uint32_t*)vo;
argType = atInt;
}
void dotori::set(float val){
void * vo = &val;
value = *(uint32_t*)vo;
argType = atFloat;
}
void dotori::set(long val){
void * vo = &val;
value = *(uint32_t*)vo;
argType = atLong;
}
void dotori::set(double val){
void * vo = &val;
value = *(uint32_t*)vo;
argType = atDouble;
}
void sgnDev::init(char *id,char *devcode,IPAddress local_ip){
addr = local_ip;
init();
devCode = devcode;
ID = id;
DEBUG_PRINT(devCode);
delay(1000);
DEBUG_PRINT("connecting....");
}
void sgnDev::init(){
if(Ethernet.begin(mac) == 0){
DEBUG_PRINT("fail using dhcp");
Ethernet.begin(mac,addr);
}
}
void sgnDev::setRest(unsigned long rest){
restTime = rest < REST? REST:rest;
}
void sgnDev::setmac(byte a,byte b,byte c,byte d,byte e,byte f){
mac[0] = a;
mac[1] = b;
mac[2] = c;
mac[3] = d;
mac[4] = e;
mac[5] = f;
}
int sgnDev::send(dotori mdotori, ...){//iot_up 소스코드 수정해야함 -> 수정완료.
//return 1;
//send value code 아래쪽 부터.
unsigned long now = millis();
if(state != 0){
if(now <= sTime){
unsigned long lastTime = 0xffffffff - sTime;
if((lastTime + now < restTime)){
return WAIT;
}
}else if(now - sTime < restTime){
return WAIT;
}
}
if (client.connect(SERVER, 80)) {
DEBUG_PRINT("connected");
//client.flush();
client.print("GET /iot/iot_up.php?");
client.print("uid=");client.print(ID);
client.print("&dc=");client.print(devCode);
int cnt = 0;
va_list vl;
va_start(vl,mdotori);
for(dotori m = mdotori;m.chk == 42;m= va_arg(vl,dotori)){
uint32_t value = m.value;
void * vo = &m.value;
client.print("&sc");client.print(cnt);client.print("=");
client.print(m.senCode);
client.print("&sv");client.print(cnt);client.print("=");
client.print(MACHTYPE(vo,m.argType));
//
/*#ifdef DEBUG
Serial.print("&sc");Serial.print(cnt);Serial.print("=");
Serial.print(m.senCode);
Serial.print("&sv");Serial.print(cnt);Serial.print("=");
Serial.println(MACHTYPE(vo,m.argType));
#endif*/
//
cnt++;
}
va_end(vl);
client.print(" HTTP/1.0\r\n");
client.print("Host:veyrobotics.cafe24.com \r\n");
client.print("User-Agent: sgnhi\r\n");
client.print("Connection: close\r\n");
client.println();
//Serial.println();
state = client.status() == 0?0:1;
//state = client.status() == 0?0:1;
//while(client.connected());
client.stop();
sTime = now;
}
else {
Serial.println(client.status());
client.stop();
DEBUG_PRINT("connection failed");
DEBUG_PRINT("try to begin");
init();
state = 0;
return ERROR;
}
return OK;
}
sgnDev dev;
EthernetClient client;