質問編集履歴

1

プログラムに間違いがあったので修正しました。

2022/02/22 11:08

投稿

raspypy
raspypy

スコア247

test CHANGED
@@ -1 +1 @@
1
- ESP32 MQTT Publish
1
+ Arduino MQTT Publish
test CHANGED
@@ -5,18 +5,6 @@
5
5
 
6
6
  ```txt
7
7
  Test24:86:1: error: expected '}' at end of input
8
-
9
- }
10
-
11
- ^
12
-
13
- 「SoftwareSerial.h」に対して複数のライブラリが見つかりました
14
-
15
- 使用済:C:\Users\PLC\Documents\Arduino\libraries\EspSoftwareSerial
16
-
17
- 未使用:C:\Users\PLC\Documents\Arduino\libraries\espsoftwareserial-master
18
-
19
- exit status 1
20
8
 
21
9
  'WiFiClient' does not name a type
22
10
  ```
@@ -29,26 +17,6 @@
29
17
  #include "esp_sleep.h"
30
18
  #include "bme280_i2c.h"
31
19
  #include <SoftwareSerial.h>
32
-
33
- #define S_PERIOD 300 // Silent period
34
-
35
- #define SDA 21
36
- #define SCL 22
37
-
38
- static const unsigned long PUSH_SHORT = 100;
39
- SoftwareSerial SwSerial(23, 4); // RX, TX
40
-
41
- //Wi-Fi Settings
42
- const char* ssid = "xxxx";
43
- const char* password = "hogehoge";
44
-
45
- //MQTT setting
46
- const char* mqttHost = "192.168.3.50";
47
- const int mqttPort = 1883; // MQTTのポート
48
- WiFiClient wificlient;
49
- PubSubClient mqttClient(wificlient);
50
- const char* topic = "yisPIP"; // Topic
51
- char* payload; // Data
52
20
 
53
21
  void setup(){
54
22
  Serial.begin(115200);
@@ -72,17 +40,4 @@
72
40
  delay(1000);
73
41
  }
74
42
 
75
- void loop(){
76
- unsigned long gauge = 0;
77
- while (digitalRead(SW) == 0) {
78
- gauge++;
79
- delay(0);
80
- }
81
- if (gauge > PUSH_SHORT) {
82
- payload = "Hello yisPIP";
83
- mqttClient.publish(topic, payload);
84
- }
85
- delay(100);
86
- mqttClient.loop();
87
- }
88
43
  ```