This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright (c) Cesanta Software Limited | |
| // All rights reserved | |
| // SPDX-License-Identifier: MIT | |
| // Usage example (Arduino): | |
| // char buf[100]; | |
| // struct slip slip = {.buf = buf, .size = sizeof(buf) - 1}; | |
| // ... | |
| // unsigned char c = Serial.read(); | |
| // size_t len = slip_recv(c, &slip); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <sttdef.h> | |
| // Single producer, single consumer non-blocking queue | |
| // | |
| // Producer: | |
| // void *buf; | |
| // while (mg_queue_space(q, &buf, len) == 0) WAIT(); // Wait for free space | |
| // memcpy(buf, data, len); // Copy data to the queue | |
| // mg_queue_add(q, len); // Advance q->head | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Single producer, single consumer non-blocking queue | |
| // | |
| // Producer: | |
| // void *buf; | |
| // while (mg_queue_space(q, &buf, len) == 0) WAIT(); // Wait for free space | |
| // memcpy(buf, data, len); // Copy data to the queue | |
| // mg_queue_add(q, len); // Advance q->head | |
| // | |
| // Consumer: | |
| // void *buf; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title>modal</title> | |
| <meta charset="utf-8" /> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.0/css/bootstrap.min.css" /> | |
| </head> | |
| <body></body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Blink LED | |
| 2 = pin // pin = 2 | |
| 0 = on // on = 0 | |
| pin 2 G // gpio.mode(pin, OUTPUT) | |
| 1000 { !on = on pin on W } T | |
| 'mqtt://broker.hivemq.com:1883' M = c | |
| c 'elk/rx' { | |
| 'topic' $1 'message' $2 '{%Q:%Q, %Q:%Q}' c P // mqtt.publish | |
| } S // mqtt.subscribe(c, topic, func) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <style> | |
| * { box-sizing: border-box; } | |
| body, html { padding: 0; margin: 0; } | |
| .main { height: 100vh; } | |
| .content { padding: 1em; } | |
| .split { display: flex; flex-grow: 1; flex-shrink: 1; width: 100%; height: 100%; box-sizing: border-box; } | |
| .split>* { flex-grow: 1; flex-shrink: 1; width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This file contains two sketches for the end-user networking API that implements | |
| // a simple WS service: WS message with JSON input {"pin": 12, "val": 0}, and JSON response {"status": true} | |
| // WS handler, streaming API (think AVR) | |
| // We don't buffer an incoming WS message. Instead, we feed | |
| // TCP stack, and user handler, byte-by-byte. | |
| // Some important values from the parsed HTTP header gets stored | |
| // and passed to the user handler. | |
| void ws_handler(struct conn *c, int event, size_t content_len, size_t receided_so_far, uint8_t byte) { | |
| if (event == EVENT_INCOMING_BYTE) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The stack has two API: low level and high level | |
| // Low level: used to hook it up to a hardware, to send/receive MAC frames | |
| // High level: used to implement network apps, like HTTP/MQTT client/servers. | |
| // Low level | |
| // A device code does something like this: | |
| // | |
| // void cnip_mac_out(char *buf, size_t len) { | |
| // bitbang_to_ethernet(buf, len); // Push outgoing frame to the network | |
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const port = 8002; | |
| const http = require('http'); | |
| const http_handler = function(req, res) { | |
| let request = '', count = 0; | |
| req.on('data', chunk => request += chunk); | |
| req.on('end', function(ev) { | |
| res.writeHead(200); | |
| const f = function() { | |
| res.write('hi\n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <style> | |
| div {} | |
| :root { --bgColor: orange; } | |
| .panel { background: var(--bgColor); } | |
| </style> |