mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-25 22:20:49 +08:00
More PPP nitpicks
This commit is contained in:
parent
fb6dfbcd3c
commit
78900304bf
@ -14,8 +14,6 @@
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
#define MG_TLS MG_TLS_BUILTIN
|
||||
#define MG_IO_SIZE 128
|
||||
|
||||
// Enable TLS
|
||||
// #define MG_TLS MG_TLS_BUILTIN
|
||||
// #define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <SoftwareSerial.h>
|
||||
#include "mongoose.h"
|
||||
|
||||
#define MQTT_SERVER "mqtt://broker.hivemq.com:1883"
|
||||
#define MQTT_SERVER "mqtts://broker.hivemq.com:8883"
|
||||
#define MQTT_SUB_TOPIC "mg/rx" // Subscribe to this topic
|
||||
#define MQTT_PUB_TOPIC "mg/tx" // Publish to this topic
|
||||
|
||||
@ -15,6 +15,10 @@ static const char *script[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
// Visit https://mongoose.ws/tls/ and copy-paste CA certificate for your server
|
||||
#define TLS_CA \
|
||||
""
|
||||
|
||||
// We use Serial1 or software serial to communicate with the modem
|
||||
#define LED_PIN LED_BUILTIN
|
||||
#define RST_PIN 10
|
||||
@ -31,6 +35,11 @@ struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // Network interface
|
||||
uint64_t mg_millis(void) {
|
||||
return millis();
|
||||
}
|
||||
bool mg_random(void *buf, size_t len) { // For TLS
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
while (len--) *p++ = (unsigned char) (rand() & 255);
|
||||
return true;
|
||||
}
|
||||
|
||||
void mqtt_publish(const char *message) {
|
||||
struct mg_mqtt_opts opts = {};
|
||||
@ -50,6 +59,11 @@ void handle_command(struct mg_str msg) {
|
||||
}
|
||||
|
||||
static void mqtt_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_CONNECT && mg_url_is_ssl(MQTT_SERVER)) {
|
||||
struct mg_tls_opts opts = {};
|
||||
opts.ca = mg_str(TLS_CA);
|
||||
mg_tls_init(c, &opts);
|
||||
}
|
||||
if (ev == MG_EV_MQTT_OPEN) {
|
||||
MG_INFO(("%lu CONNECTED to %s", c->id, MQTT_SERVER));
|
||||
struct mg_mqtt_opts opts = {};
|
||||
|
@ -18095,7 +18095,7 @@ static size_t mg_ppp_rx(void *ethbuf, size_t ethlen, struct mg_tcpip_if *ifp) {
|
||||
case MG_PPP_PROTO_LCP: mg_ppp_handle_lcp(ifp, buf + 4, bufsz - 4); break;
|
||||
case MG_PPP_PROTO_IPCP: mg_ppp_handle_ipcp(ifp, buf + 4, bufsz - 4); break;
|
||||
case MG_PPP_PROTO_IP:
|
||||
MG_DEBUG(("got IP packet of %d bytes", bufsz - 4));
|
||||
MG_VERBOSE(("got IP packet of %d bytes", bufsz - 4));
|
||||
memmove(eth + 14, buf + 4, bufsz - 4);
|
||||
memmove(eth, ifp->mac, 6);
|
||||
memmove(eth + 6, "\xff\xff\xff\xff\xff\xff", 6);
|
||||
|
@ -301,7 +301,7 @@ static size_t mg_ppp_rx(void *ethbuf, size_t ethlen, struct mg_tcpip_if *ifp) {
|
||||
case MG_PPP_PROTO_LCP: mg_ppp_handle_lcp(ifp, buf + 4, bufsz - 4); break;
|
||||
case MG_PPP_PROTO_IPCP: mg_ppp_handle_ipcp(ifp, buf + 4, bufsz - 4); break;
|
||||
case MG_PPP_PROTO_IP:
|
||||
MG_DEBUG(("got IP packet of %d bytes", bufsz - 4));
|
||||
MG_VERBOSE(("got IP packet of %d bytes", bufsz - 4));
|
||||
memmove(eth + 14, buf + 4, bufsz - 4);
|
||||
memmove(eth, ifp->mac, 6);
|
||||
memmove(eth + 6, "\xff\xff\xff\xff\xff\xff", 6);
|
||||
|
Loading…
x
Reference in New Issue
Block a user