Skip to content

Commit

Permalink
release 1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Lyubka committed May 8, 2019
1 parent cb317de commit 7f0861b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
22 changes: 0 additions & 22 deletions examples/ControlLedViaApp/ControlLedViaApp.ino

This file was deleted.

41 changes: 41 additions & 0 deletions examples/PWA/PWA.ino
@@ -0,0 +1,41 @@
#include <mDash.h>

#define LED_PIN 5

#define WIFI_NAME "YOUR_WIFI_NETWORK"
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
#define DEVICE_ID "DEVICE_ID"
#define DEVICE_TOKEN "DEVICE_TOKEN"

static const char *s_topic = DEVICE_ID "/shadow/update"; // Shadow update topic

static void onShadowDelta(const char *topic, const char *message) {
static int led = 0, cnt = 0;
double v = 0;
printf("DELTA: %s\n", message);
if (mDashGetBool(message, "$.state.lights", &led)) {
pinMode(LED_PIN, OUTPUT); // A toggle button has been changed state.
digitalWrite(LED_PIN, led); // Set the LED pin accordingly
}
if (mDashGetNum(message, "$.state.reboot", &v)) {
if (cnt == 0) { // If the reboot counter is not initialised
cnt = v; // Then initialise it to the current value in a shadow
} else { // Otherwise, the button was pressed on the app
*(int *) 0 = 42; // therefore crash by writing to the zero address
}
}
mDashPublish(s_topic, "{%Q:{%Q:{%Q:%B,%Q:%d}}}", "state", "reported",
"lights", led, "reboot", cnt);
}

void setup() {
Serial.begin(115200);
mDashStartWithWifi(WIFI_NAME, WIFI_PASS, DEVICE_ID, DEVICE_TOKEN);
mDashSubscribe(DEVICE_ID "/shadow/delta", onShadowDelta);
}

void loop() {
delay(1000); // Sleep 1 second, then report a (simulated) temperature
mDashPublish(s_topic, "{%Q:{%Q:{%Q:%g}}}", "state", "reported", "temp",
20 + (double) rand() / RAND_MAX * 5.0);
}
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=mDash
version=1.0.10
version=1.0.11
author=Cesanta Software Limited <support@cesanta.com>
maintainer=Cesanta Software Limited <support@cesanta.com>
sentence=Remote control and OTA for ESP32 via mdash.net IoT backend
Expand Down
Binary file modified src/esp32/libmDash.a
Binary file not shown.
7 changes: 5 additions & 2 deletions src/mDash.h
Expand Up @@ -11,16 +11,19 @@ extern "C" {
mDashInitWithWifi((a), (b), (c), (d), __FILE__)
#define mDashStart(a, b) mDashInit((a), (b), __FILE__)

enum { MDASH_EV_CONNECTED, MDASH_EV_DISCONNECTED };

// mDash housekeeping
void mDashInitWithWifi(const char *wifi_name, const char *wifi_pass,
const char *device_id, const char *device_pass,
const char *app_name);
void mDashInit(const char *id, const char *pass, const char *app_name);
void mDashOn(void (*fn)(int, void *), void *);
void mDashSetLogLevel(int logLevel); // 0 - no logs, 3 - debug logs
const char *mDashGetDeviceID(void);

// MQTT API
bool mDashPublish(const char *topic, const char *message);
bool mDashPublish(const char *topic, const char *message_fmt, ...);
void mDashSubscribe(const char *topic, void (*fn)(const char *, const char *));

// RPC API
Expand All @@ -33,7 +36,7 @@ const char *mDashGetParams(void *ctx);
int mDashGetNum(const char *json, const char *json_path, double *value);
int mDashGetStr(const char *json, const char *json_path, char *dst, int len);
int mDashGetBase64(const char *json, const char *json_path, char *dst, int len);
int mDashGetBool(const char *json, const char *json_path, char *dst, int len);
int mDashGetBool(const char *json, const char *json_path, int *);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 7f0861b

Please sign in to comment.