Skip to content

Commit 4a99d72

Browse files
committed
no special install script
1 parent 591c4fe commit 4a99d72

File tree

5 files changed

+30
-43
lines changed

5 files changed

+30
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ set(SOURCE_FILES
3535
src/YunMQTTClient.cpp
3636
src/YunMQTTClient.h
3737
examples/MQTTClient/MQTTClient.ino
38-
examples/YunMQTTClient/YunMQTTClient.ino
39-
examples/YunMQTTInstall/YunMQTTInstall.ino)
38+
examples/YunMQTTClient/YunMQTTClient.ino)
4039

4140
add_executable(arduino_mqtt ${SOURCE_FILES})

examples/YunMQTTClient/YunMQTTClient.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ unsigned long lastMillis = 0;
88
void setup() {
99
Bridge.begin();
1010
Serial.begin(9600);
11+
12+
// this will install the required python files (pass true to force download)
13+
// can also be commented out to save program space
14+
client.installBridge(false);
15+
1116
Serial.println("connecting...");
1217
if (client.connect("arduino", "demo", "demo")) {
1318
Serial.println("connected!");

examples/YunMQTTInstall/YunMQTTInstall.ino

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/YunMQTTClient.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
#include "YunMQTTClient.h"
22

3+
#include <FileIO.h>
4+
35
YunMQTTClient::YunMQTTClient(const char * _hostname, int _port) {
46
this->hostname = _hostname;
57
this->port = _port;
68
}
79

10+
boolean YunMQTTClient::installBridge(boolean force) {
11+
if(!force) {
12+
boolean f1 = FileSystem.exists("/usr/mqtt/mqtt.py");
13+
boolean f2 = FileSystem.exists("/usr/mqtt/bridge.py");
14+
15+
if(f1 && f2) {
16+
return true;
17+
}
18+
}
19+
20+
Process p;
21+
22+
int r1 = p.runShellCommand("mkdir -p /usr/mqtt");
23+
int r2 = p.runShellCommand("wget https://raw.githubusercontent.com/256dpi/arduino-mqtt/yun/mqtt.py --no-check-certificate -O /usr/mqtt/mqtt.py");
24+
int r3 = p.runShellCommand("wget https://raw.githubusercontent.com/256dpi/arduino-mqtt/yun/bridge.py --no-check-certificate -O /usr/mqtt/bridge.py");
25+
26+
return r1 == 0 && r2 == 0 && r3 == 0;
27+
}
28+
829
boolean YunMQTTClient::connect(const char * clientId) {
930
return this->connect(clientId, "", "");
1031
}
1132

1233
boolean YunMQTTClient::connect(const char * clientId, const char * username, const char * password) {
1334
this->process.begin("python");
1435
this->process.addParameter("-u");
15-
this->process.addParameter("/usr/client.py");
36+
this->process.addParameter("/usr/mqtt/bridge.py");
1637
this->process.runAsynchronously();
1738
this->process.setTimeout(10000);
1839

src/YunMQTTClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define YUN_MQTT_CLIENT_H
33

44
#include <Arduino.h>
5-
#include <Process.h>
5+
#include <Bridge.h>
66

77
void messageReceived(String topic, String payload, char * bytes, unsigned int length);
88

@@ -14,6 +14,7 @@ class YunMQTTClient {
1414
boolean alive = false;
1515
public:
1616
YunMQTTClient(const char * hostname, int port);
17+
boolean installBridge(boolean force);
1718
boolean connect(const char * clientId);
1819
boolean connect(const char * clientId, const char* username, const char* password);
1920
void publish(String topic);

0 commit comments

Comments
 (0)