質問編集履歴

2

phpのコードの一部を追記

2017/04/06 07:57

投稿

bobby2128
bobby2128

スコア42

test CHANGED
File without changes
test CHANGED
@@ -181,3 +181,27 @@
181
181
  }
182
182
 
183
183
  ```
184
+
185
+
186
+
187
+ phpのうちファイル書き込み用命令文
188
+
189
+ ```php
190
+
191
+
192
+
193
+ $Temp = $_POST["temperature"];
194
+
195
+ $Write = "<p>Temperature :" . $_POST["temperature"] . "</p><br>";
196
+
197
+
198
+
199
+ $fp = @fopen("write.txt", "w") ;
200
+
201
+ fputs($fp, $Write);
202
+
203
+ fclose($fp);
204
+
205
+
206
+
207
+ ```

1

プログラムの追記

2017/04/06 07:57

投稿

bobby2128
bobby2128

スコア42

test CHANGED
File without changes
test CHANGED
@@ -5,3 +5,179 @@
5
5
 
6
6
 
7
7
  何か参考になるアイデアや資料などございましたらご教授お願いいたします。
8
+
9
+
10
+
11
+ ```c
12
+
13
+ /*****************************Wifi,Setting***************************/
14
+
15
+ // ライブラリの読み込み
16
+
17
+ #include "ESP8266.h"
18
+
19
+ #include "Milkcocoa.h"
20
+
21
+ #include "Client_ESP8266.h"
22
+
23
+ // 転送スピード
24
+
25
+ #define SERIAL_SPEED 115200
26
+
27
+ /************************* WiFi Access Point *********************************/
28
+
29
+ // Wi-Fi SSID
30
+
31
+ #define WLAN_SSID "D********"
32
+
33
+ // Wi-Fi PASSWORD
34
+
35
+ #define WLAN_PASS "e********"
36
+
37
+ ESP8266Client wifi;
38
+
39
+
40
+
41
+ String data;
42
+
43
+ String server = "p******.scm.azurewebsites.net";
44
+
45
+
46
+
47
+ String uri = "/dev/wwwroot/SQL_SEND.php";
48
+
49
+
50
+
51
+ byte dat [5];
52
+
53
+ String temp ,hum;
54
+
55
+
56
+
57
+ /********************************** Setup ***************************************/
58
+
59
+ void setup() {
60
+
61
+ // パソコンとのシリアル通信のポートを開ける
62
+
63
+ Serial.begin(SERIAL_SPEED);
64
+
65
+ // Wi-Fiモジュールとのシリアル通信のポートを開ける
66
+
67
+ Serial1.begin(SERIAL_SPEED); /
68
+
69
+ // Wi-Fi設定
70
+
71
+ setupWiFi();
72
+
73
+ }
74
+
75
+
76
+
77
+ /* setupWiFi(); Wifi接続部 省略*/
78
+
79
+
80
+
81
+
82
+
83
+ void loop () {
84
+
85
+ hum= "1";
86
+
87
+ temp="2";
88
+
89
+ data = "temperature=" + temp;// + "&humidity=" + hum;// data sent must be under this form //name1=value1&name2=value2.
90
+
91
+ httppost();
92
+
93
+ delay(1000);
94
+
95
+ }
96
+
97
+
98
+
99
+ void httppost () {
100
+
101
+ Serial1.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
102
+
103
+ // Serial.println("TCP connection try");
104
+
105
+
106
+
107
+ if( Serial1.find("OK")) {
108
+
109
+ Serial.println("TCP connection ready");
110
+
111
+ }
112
+
113
+ delay(1000);
114
+
115
+
116
+
117
+ String postRequest =
118
+
119
+ "POST " + uri + " HTTP/1.0\r\n" +
120
+
121
+ "Host: " + server + "\r\n" +
122
+
123
+ "Accept: *" + "/" + "*\r\n" +
124
+
125
+ "Content-Length: " + data.length() + "\r\n" +
126
+
127
+ "Content-Type: application/x-www-form-urlencoded\r\n" +
128
+
129
+ "\r\n" + data;
130
+
131
+ Serial.println(data);
132
+
133
+ // Serial.println(postRequest);
134
+
135
+
136
+
137
+
138
+
139
+ String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
140
+
141
+
142
+
143
+ Serial1.print(sendCmd);
144
+
145
+ Serial1.println(postRequest.length() );
146
+
147
+ delay(500);
148
+
149
+
150
+
151
+ if(Serial1.find(">")) {
152
+
153
+ Serial.println("Sending..");
154
+
155
+ Serial1.print(postRequest);
156
+
157
+
158
+
159
+ if( Serial1.find("SEND OK")) {
160
+
161
+ Serial.println("Packet sent");
162
+
163
+ while (Serial1.available()) {
164
+
165
+ String tmpResp = Serial1.readString();
166
+
167
+ Serial.println(tmpResp);
168
+
169
+ }
170
+
171
+
172
+
173
+ // close the connection
174
+
175
+ Serial1.println("AT+CIPCLOSE");
176
+
177
+ }
178
+
179
+ }
180
+
181
+ }
182
+
183
+ ```