Skip to content

Commit

Permalink
release 1.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Sep 14, 2020
1 parent 84d5897 commit 109a343
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 22 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Arduino / ESP-IDF client library for mdash.net

See [Documentation](https://mdash.net/docs/) for the quick start guide.

NOTE: for Arduino 1.8.10 and later, please make the following changes:

- Change `platform.txt` as in [this PR](https://github.com/espressif/arduino-esp32/pull/4209/commits/183964aa93b7039d11813fd60aba7e8170caa4b8)
- Change `library.properties` by commenting out the `ldflags=-lmDash` line
42 changes: 42 additions & 0 deletions examples/Cli/Cli.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This Arduino sketch demonstrates how to use Serial CLI to configure your
// device. Devices that are configured via CLI (or via WiFi Access Point)
// store their credentials in the config file, rather than hardcoding them
// into firmware code. That allows to have a fleet of devices, and OTA them
// using the same firmware.
//
// - Install mDash library:
// - Select "Sketch" → "Include Library" → "Manage Libraries"
// - In the search field, type "mDash" and press Enter
// - Click on "Install" to install the library
// - Select "Tools" → "Board" → "ESP32 Dev Module"
// - Select "Tools" → "Partitioning Scheme" → "Minimal SPIFFS"
// - Select "Tools" → "Port" → your serial port
// - Click on "Upload" button to build and flash the firmware
//
// Start Serial monitor, enter the following commands:
// set wifi.sta.ssid YOUR_WIFI_NETWORK
// set wifi.sta.pass YOUR_WIFI_PASSWORD
// set device.pass MDASH_DEVICE_PASSWORD
// reboot
//
// When done, your device should become online on mdash.net.
// See https://mdash.net/docs/ for more.

#define MDASH_APP_NAME "CliApp"
#include <mDash.h>

#include <WiFi.h>

static void initWiFi(const char *ssid, const char *pass) {
if (ssid != NULL) WiFi.begin(ssid, pass); // WiFi is configured, join
if (ssid == NULL) WiFi.softAP("CliAP"); // Not configured, start AP
}

void setup() {
Serial.begin(115200);
mDashBeginWithWifi(initWiFi, NULL, NULL, NULL);
}

void loop() {
if (Serial.available() > 0) mDashCLI(Serial.read());
}
4 changes: 2 additions & 2 deletions examples/GpioReadWrite/GpioReadWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
static void handleGpioRead(struct jsonrpc_request *r) {
double pin;
if (mjson_get_number(r->params, r->params_len, "$.pin", &pin)) {
pinMode(pin, OUTPUT);
pinMode(pin, INPUT);
jsonrpc_return_success(r, "%d", digitalRead(pin));
} else {
jsonrpc_return_error(r, JSONRPC_ERROR_BAD_PARAMS, "pin required", NULL);
Expand All @@ -34,7 +34,7 @@ static void handleGpioWrite(struct jsonrpc_request *r) {
double pin, value;
if (mjson_get_number(r->params, r->params_len, "$.pin", &pin) &&
mjson_get_number(r->params, r->params_len, "$.value", &value)) {
pinMode(pin, INPUT);
pinMode(pin, OUTPUT);
digitalWrite(pin, value);
jsonrpc_return_success(r, "true");
} else {
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=mDash
version=1.2.10
version=1.2.11
author=Cesanta Software Limited <[email protected]>
maintainer=Cesanta Software Limited <[email protected]>
sentence=Remote control and OTA for ESP32 via mdash.net IoT backend
Expand All @@ -9,4 +9,4 @@ url=https://github.com/cesanta/mDash
architectures=esp32,esp8266
includes=mDash.h
precompiled=true
ldflags=-lmDash
#ldflags=-lmDash
13 changes: 7 additions & 6 deletions other/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include <time.h>
#include <unistd.h>

#include "mongoose.h"

#include "mDash.h"

static int s_stop;

static void sighandler(int sig) {
MLOG(LL_CRIT, "Got signal %d, exiting...", sig);
LOG(LL_CRIT, ("Got signal %d, exiting...", sig));
s_stop = 1;
}

Expand All @@ -35,28 +37,27 @@ static void onJsEval(struct jsonrpc_request *r) {

int main(int argc, char *argv[]) {
const char *wifi = "", *pass = NULL, *url = NULL, *report_interval = "5";
time_t start = time(NULL);

for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--pass") == 0) {
pass = argv[++i];
} else if (strcmp(argv[i], "--url") == 0) {
url = argv[++i];
} else if (strcmp(argv[i], "--log-level") == 0) {
mDashSetLogLevel(atoi(argv[++i]));
mDashSetLogLevel(strdup(argv[++i]));
} else if (strcmp(argv[i], "--report-interval") == 0) {
report_interval = argv[++i];
} else if (strcmp(argv[i], "--ap") == 0) {
wifi = NULL; // if WiFi is NULL, mDash lib starts HTTP server
} else {
MLOG(LL_CRIT, "Invalid option: [%s]\n", argv[i]);
MLOG(LL_CRIT, "Usage: %s --pass DEVICE_PASSWORD", argv[0]);
LOG(LL_CRIT, ("Invalid option: [%s]\n", argv[i]));
LOG(LL_CRIT, ("Usage: %s --pass DEVICE_PASSWORD", argv[0]));
return 1;
}
}

if (pass == NULL) {
MLOG(LL_CRIT, "%s", "Please specify --pass DEVICE_PASSWORD");
LOG(LL_CRIT, ("%s", "Please specify --pass DEVICE_PASSWORD"));
return 1;
}

Expand Down
Binary file modified src/esp32/libmDash.a
Binary file not shown.
Binary file modified src/esp8266/libmDash.a
Binary file not shown.
Binary file modified src/linux-x64/libmDash.a
Binary file not shown.
71 changes: 59 additions & 12 deletions src/mDash.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void mDashInit(const char *device_id, const char *device_pass,
const char *app_name, const char *build_time,
const char *framework);

void mDashSetLogLevel(int logLevel);
void mDashSetLogLevel(const char *logLevel);
void mDashSetURL(const char *);
int mDashGetState(void); // current connection state, MDASH_EVENT_*
const char *mDashGetSdkVersion(void);
Expand All @@ -68,9 +68,11 @@ void mDashRegisterEventHandler(int event, evh_t fn, void *userdata);
int mDashTriggerEvent(int event, void *event_data);

// Logging API
#ifndef MG_VERSION
enum { LL_NONE, LL_CRIT, LL_INFO, LL_DEBUG };
#define MLOG(ll, fmt, ...) mlog(ll, __func__, (fmt), __VA_ARGS__)
void mlog(int ll, const char *fn, const char *fmt, ...);
#endif

// Data storage
int mDashStore(const char *topic, const char *json_fmt, ...);
Expand All @@ -89,7 +91,7 @@ int mDashConfigSet(const char *name, const char *value);
int mDashConfigReset(void);
void mDashCLI(unsigned char input_byte);

// mjson API - see documentation at https://github.com/cesanta/mjson
// See https://github.com/cesanta/mjson
#ifndef MJSON_H
#define MJSON_H

Expand All @@ -110,6 +112,23 @@ void mDashCLI(unsigned char input_byte);
#define MJSON_ENABLE_BASE64 1
#endif

#ifndef MJSON_ENABLE_MERGE
#define MJSON_ENABLE_MERGE 0
#elif MJSON_ENABLE_MERGE
#define MJSON_ENABLE_NEXT 1
#endif

#ifndef MJSON_ENABLE_PRETTY
#define MJSON_ENABLE_PRETTY 0
#elif MJSON_ENABLE_PRETTY
#define MJSON_ENABLE_NEXT 1
#endif

#ifndef MJSON_ENABLE_NEXT
#define MJSON_ENABLE_NEXT 0
#endif


#ifndef MJSON_RPC_IN_BUF_SIZE
#define MJSON_RPC_IN_BUF_SIZE 256
#endif
Expand All @@ -118,6 +137,14 @@ void mDashCLI(unsigned char input_byte);
#define ATTR
#endif

#ifndef MJSON_RPC_LIST_NAME
#define MJSON_RPC_LIST_NAME "rpc.list"
#endif

#ifdef __cplusplus
extern "C" {
#endif

enum {
MJSON_ERROR_INVALID_INPUT = -1,
MJSON_ERROR_TOO_DEEP = -2,
Expand All @@ -136,7 +163,7 @@ enum mjson_tok {
};
#define MJSON_TOK_IS_VALUE(t) ((t) > 10 && (t) < 20)

typedef void (*mjson_cb_t)(int ev, const char *s, int off, int len, void *ud);
typedef int (*mjson_cb_t)(int ev, const char *s, int off, int len, void *ud);

#ifndef MJSON_MAX_DEPTH
#define MJSON_MAX_DEPTH 20
Expand All @@ -148,9 +175,16 @@ enum mjson_tok mjson_find(const char *s, int len, const char *jp,
int mjson_get_number(const char *s, int len, const char *path, double *v);
int mjson_get_bool(const char *s, int len, const char *path, int *v);
int mjson_get_string(const char *s, int len, const char *path, char *to, int n);
int mjson_get_hex(const char *s, int len, const char *path, char *to, int n);

#if MJSON_ENABLE_NEXT
int mjson_next(const char *s, int n, int off, int *koff, int *klen, int *voff,
int *vlen, int *vtype);
#endif

#if MJSON_ENABLE_BASE64
int mjson_get_base64(const char *s, int len, const char *path, char *to, int n);
int mjson_base64_dec(const char *src, int n, char *dst, int dlen);
#endif

#if MJSON_ENABLE_PRINT
Expand All @@ -167,23 +201,37 @@ int mjson_vprintf(mjson_print_fn_t, void *, const char *fmt, va_list ap);
int mjson_print_str(mjson_print_fn_t, void *, const char *s, int len);
int mjson_print_int(mjson_print_fn_t, void *, int value, int is_signed);
int mjson_print_long(mjson_print_fn_t, void *, long value, int is_signed);
int mjson_print_buf(mjson_print_fn_t fn, void *, const char *buf, int len);

int mjson_print_null(const char *ptr, int len, void *userdata);
int mjson_print_file(const char *ptr, int len, void *userdata);
int mjson_print_fixed_buf(const char *ptr, int len, void *userdata);
int mjson_print_dynamic_buf(const char *ptr, int len, void *userdata);

#if MJSON_ENABLE_PRETTY
int mjson_pretty(const char *, int, const char *, mjson_print_fn_t, void *);
#endif

#if MJSON_ENABLE_MERGE
int mjson_merge(const char *, int, const char *, int, mjson_print_fn_t, void *);
#endif

#endif // MJSON_ENABLE_PRINT

#if MJSON_ENABLE_RPC

void jsonrpc_init(void (*response_cb)(const char *, int, void *),
void *userdata);
void jsonrpc_init(mjson_print_fn_t, void *userdata);
int mjson_globmatch(const char *s1, int n1, const char *s2, int n2);

struct jsonrpc_request {
const char *frame; // Points to the whole frame
int frame_len; // Frame length
const char *params; // Points to the "params" in the request frame
int params_len; // Length of the "params"
const char *id; // Points to the "id" in the request frame
int id_len; // Length of the "id"
const char *method; // Points to the "method" in the request frame
int method_len; // Length of the "method"
mjson_print_fn_t fn; // Printer function
void *fndata; // Printer function data
void *userdata; // Callback's user data as specified at export time
Expand All @@ -202,7 +250,7 @@ struct jsonrpc_method {
struct jsonrpc_ctx {
struct jsonrpc_method *methods;
void *userdata;
void (*response_cb)(const char *buf, int len, void *userdata);
mjson_print_fn_t response_cb;
int in_len;
char in[MJSON_RPC_IN_BUF_SIZE];
};
Expand All @@ -216,15 +264,12 @@ struct jsonrpc_ctx {
(ctx)->methods = &m; \
} while (0)

void jsonrpc_ctx_init(struct jsonrpc_ctx *ctx,
void (*response_cb)(const char *, int, void *),
void *userdata);
int jsonrpc_call(mjson_print_fn_t fn, void *fndata, const char *fmt, ...);
void jsonrpc_ctx_init(struct jsonrpc_ctx *ctx, mjson_print_fn_t, void *);
void jsonrpc_return_error(struct jsonrpc_request *r, int code,
const char *message, const char *data_fmt, ...);
void jsonrpc_return_success(struct jsonrpc_request *r, const char *result_fmt,
...);
void jsonrpc_ctx_process(struct jsonrpc_ctx *ctx, char *req, int req_sz,
void jsonrpc_ctx_process(struct jsonrpc_ctx *ctx, const char *req, int req_sz,
mjson_print_fn_t fn, void *fndata);
void jsonrpc_ctx_process_byte(struct jsonrpc_ctx *ctx, unsigned char ch,
mjson_print_fn_t fn, void *fndata);
Expand All @@ -246,9 +291,11 @@ extern struct jsonrpc_ctx jsonrpc_default_context;
#define JSONRPC_ERROR_INTERNAL -32603 /* Internal JSON-RPC error */

#endif // MJSON_ENABLE_RPC
#ifdef __cplusplus
}
#endif
#endif // MJSON_H


#ifdef __cplusplus
}
#endif
Binary file modified src/macos/libmDash.a
Binary file not shown.

0 comments on commit 109a343

Please sign in to comment.