Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一定時間経つとMilkcocoaからdisconnectされる #4

Open
syuhei176 opened this issue Dec 21, 2016 · 1 comment
Open

一定時間経つとMilkcocoaからdisconnectされる #4

syuhei176 opened this issue Dec 21, 2016 · 1 comment

Comments

@syuhei176
Copy link
Member

すごい昔のissueでいまさらですが、MQTTではclientから定期的にpingを送らないといけないので、その実装がAdafruit_MQTT.cppにない可能性が有りますね。
例えばMilkcocoa.cpp側にping APIを追加して、ユーザのタイミングでpingするとかってどうですかね?

milk-cocoa/Milkcocoa_Arduino_SDK#3

@syuhei176
Copy link
Member Author

動作確認できたコード。5分以上放置しても、Arduino側でpushを受け取れた。
AppIdはお絵かき( https://mlkcca.com/sample.html )のもの。

#include <ESP8266WiFi.h>
#include <Milkcocoa.h>

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "...SSID..."
#define WLAN_PASS       "...PASSWORD..."


/************************* Your Milkcocoa Setup *********************************/

#define MILKCOCOA_APP_ID      "dogi9jz8c16"
#define MILKCOCOA_DATASTORE   "dots"

/************* Milkcocoa Setup (you don't need to change this!) ******************/

#define MILKCOCOA_SERVERPORT  1883

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

const char MQTT_SERVER[] PROGMEM    = MILKCOCOA_APP_ID ".mlkcca.com";
const char MQTT_CLIENTID[] PROGMEM  = __TIME__ MILKCOCOA_APP_ID;

Milkcocoa milkcocoa = Milkcocoa(&client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);

void onpush(DataElement *elem) {
  Serial.println("onpush");
  Serial.println(elem->getInt("index"));
};

void setupWiFi() {
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println(F("Milkcocoa SDK demo"));

  setupWiFi();

  Serial.println( milkcocoa.on(MILKCOCOA_DATASTORE, "push", onpush) );
};

void loop() {
  milkcocoa.loop();
  milkcocoa.ping();
  delay(7000);
};

@syuhei176 syuhei176 changed the title 一定時間立つとMilkcocoaからdisconnectされる 一定時間経つとMilkcocoaからdisconnectされる Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant