Skip to content

Commit

Permalink
Make it work with Arduino 1.8.19
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Jul 2, 2022
1 parent 2824795 commit 5b1b436
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 67 deletions.
8 changes: 7 additions & 1 deletion examples/Minimal/Minimal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected, IP address:");
Serial.println(WiFi.localIP());
mDashBegin(DEVICE_PASSWORD);
}

void loop() {
delay(100);
delay(500);
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name=mDash
version=1.2.14
version=1.2.15
author=Cesanta Software Limited <[email protected]>
maintainer=Cesanta Software Limited <[email protected]>
sentence=Remote control and OTA for ESP32 via mdash.net IoT backend
paragraph=Provides OTA, MQTT, device shadow, Filesystem management for ESP32
category=Communication
url=https://github.com/cesanta/mDash
architectures=esp32,esp8266
architectures=esp32
includes=mDash.h
precompiled=true
#ldflags=-lmDash
15 changes: 8 additions & 7 deletions other/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include "mongoose.h"

#include "mDash.h"
#include "mjson.h"

static int s_stop;

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

Expand Down Expand Up @@ -50,21 +51,21 @@ int main(int argc, char *argv[]) {
} else if (strcmp(argv[i], "--ap") == 0) {
wifi = NULL; // if WiFi is NULL, mDash lib starts HTTP server
} else {
LOG(LL_CRIT, ("Invalid option: [%s]\n", argv[i]));
LOG(LL_CRIT, ("Usage: %s --pass DEVICE_PASSWORD", argv[0]));
MG_ERROR(("Invalid option: [%s]\n", argv[i]));
MG_ERROR(("Usage: %s --pass DEVICE_PASSWORD", argv[0]));
return 1;
}
}

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

mDashBeginWithWifi(NULL, wifi, NULL, pass);
jsonrpc_export("Shadow.Delta", onDelta, NULL);
jsonrpc_export("Config.Get", onConfigGet, NULL);
jsonrpc_export("JS.Eval", onJsEval, NULL);
jsonrpc_export("Shadow.Delta", onDelta );
jsonrpc_export("Config.Get", onConfigGet );
jsonrpc_export("JS.Eval", onJsEval);
if (url != NULL) mDashSetURL(url);

srand(time(0));
Expand Down
Binary file modified src/esp32/libmDash.a
Binary file not shown.
Binary file modified src/linux-x64/libmDash.a
Binary file not shown.
94 changes: 37 additions & 57 deletions src/mDash.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void mDashCLI(unsigned char input_byte);
#define MJSON_H

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Expand All @@ -113,54 +112,40 @@ void mDashCLI(unsigned char input_byte);
#endif

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

#ifndef MJSON_ENABLE_PRETTY
#define MJSON_ENABLE_PRETTY 0
#elif MJSON_ENABLE_PRETTY
#define MJSON_ENABLE_NEXT 1
#define MJSON_ENABLE_PRETTY 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

#ifndef ATTR
#define ATTR
#define MJSON_ENABLE_NEXT 1
#endif

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

#ifndef MJSON_DYNBUF_CHUNK
#define MJSON_DYNBUF_CHUNK 256 // Allocation granularity for print_dynamic_buf
#endif

#ifdef __cplusplus
extern "C" {
#endif

enum {
MJSON_ERROR_INVALID_INPUT = -1,
MJSON_ERROR_TOO_DEEP = -2,
};

enum mjson_tok {
MJSON_TOK_INVALID = 0,
MJSON_TOK_KEY = 1,
MJSON_TOK_STRING = 11,
MJSON_TOK_NUMBER = 12,
MJSON_TOK_TRUE = 13,
MJSON_TOK_FALSE = 14,
MJSON_TOK_NULL = 15,
MJSON_TOK_ARRAY = 91,
MJSON_TOK_OBJECT = 123,
};
#define MJSON_ERROR_INVALID_INPUT (-1)
#define MJSON_ERROR_TOO_DEEP (-2)
#define MJSON_TOK_INVALID 0
#define MJSON_TOK_KEY 1
#define MJSON_TOK_STRING 11
#define MJSON_TOK_NUMBER 12
#define MJSON_TOK_TRUE 13
#define MJSON_TOK_FALSE 14
#define MJSON_TOK_NULL 15
#define MJSON_TOK_ARRAY 91
#define MJSON_TOK_OBJECT 123
#define MJSON_TOK_IS_VALUE(t) ((t) > 10 && (t) < 20)

typedef int (*mjson_cb_t)(int ev, const char *s, int off, int len, void *ud);
Expand All @@ -170,8 +155,7 @@ typedef int (*mjson_cb_t)(int ev, const char *s, int off, int len, void *ud);
#endif

int mjson(const char *s, int len, mjson_cb_t cb, void *ud);
enum mjson_tok mjson_find(const char *s, int len, const char *jp,
const char **tokptr, int *toklen);
int mjson_find(const char *s, int len, const char *jp, const char **, int *);
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);
Expand All @@ -197,17 +181,20 @@ struct mjson_fixedbuf {
};

int mjson_printf(mjson_print_fn_t, void *, const char *fmt, ...);
int mjson_vprintf(mjson_print_fn_t, void *, const char *fmt, va_list ap);
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_dbl(mjson_print_fn_t fn, void *, double, int width);

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);

int mjson_snprintf(char *buf, size_t len, const char *fmt, ...);
char *mjson_aprintf(const char *fmt, ...);

#if MJSON_ENABLE_PRETTY
int mjson_pretty(const char *, int, const char *, mjson_print_fn_t, void *);
#endif
Expand All @@ -224,6 +211,7 @@ 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 {
struct jsonrpc_ctx *ctx;
const char *frame; // Points to the whole frame
int frame_len; // Frame length
const char *params; // Points to the "params" in the request frame
Expand All @@ -241,27 +229,23 @@ struct jsonrpc_method {
const char *method;
int method_sz;
void (*cb)(struct jsonrpc_request *);
void *cbdata;
struct jsonrpc_method *next;
};

// Main RPC context, stores current request information and a list of
// exported RPC methods.
struct jsonrpc_ctx {
struct jsonrpc_method *methods;
void *userdata;
mjson_print_fn_t response_cb;
int in_len;
char in[MJSON_RPC_IN_BUF_SIZE];
void *response_cb_data;
};

// Registers function fn under the given name within the given RPC context
#define jsonrpc_ctx_export(ctx, name, fn, ud) \
do { \
static struct jsonrpc_method m = {(name), sizeof(name) - 1, (fn), 0, 0}; \
m.cbdata = (ud); \
m.next = (ctx)->methods; \
(ctx)->methods = &m; \
#define jsonrpc_ctx_export(ctx, name, fn) \
do { \
static struct jsonrpc_method m = {(name), sizeof(name) - 1, (fn), 0}; \
m.next = (ctx)->methods; \
(ctx)->methods = &m; \
} while (0)

void jsonrpc_ctx_init(struct jsonrpc_ctx *ctx, mjson_print_fn_t, void *);
Expand All @@ -270,20 +254,16 @@ void jsonrpc_return_error(struct jsonrpc_request *r, int code,
void jsonrpc_return_success(struct jsonrpc_request *r, const char *result_fmt,
...);
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);
mjson_print_fn_t fn, void *fndata, void *userdata);

extern struct jsonrpc_ctx jsonrpc_default_context;
extern void jsonrpc_list(struct jsonrpc_request *r);

#define jsonrpc_export(name, fn, ud) \
jsonrpc_ctx_export(&jsonrpc_default_context, (name), (fn), (ud))

#define jsonrpc_process(buf, len, fn, data) \
jsonrpc_ctx_process(&jsonrpc_default_context, (buf), (len), (fn), (data))
#define jsonrpc_export(name, fn) \
jsonrpc_ctx_export(&jsonrpc_default_context, (name), (fn))

#define jsonrpc_process_byte(x, fn, data) \
jsonrpc_ctx_process_byte(&jsonrpc_default_context, (x), (fn), (data))
#define jsonrpc_process(buf, len, fn, fnd, ud) \
jsonrpc_ctx_process(&jsonrpc_default_context, (buf), (len), (fn), (fnd), (ud))

#define JSONRPC_ERROR_INVALID -32700 /* Invalid JSON was received */
#define JSONRPC_ERROR_NOT_FOUND -32601 /* The method does not exist */
Expand Down

0 comments on commit 5b1b436

Please sign in to comment.