This file contains 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 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 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>hiii</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/4.5.0/css/bootstrap.min.css" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script> | |
</head> |
This file contains 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
// Run this catcher in a following way: | |
// 1. Make sure to install tmux, nodejs, and `ws` node package | |
// apt-get install tmux npm | |
// npm install -g ws | |
// 2. Start tmux. This is needed to let the program run after logout. | |
// When you log in again, `tmux attach` attaches an old session. | |
// 3. Run catcher in an infinite loop: | |
// while true; do node catcher.js YOUR_API_KEY ; sleep 1; done | |
const Websocket = require('ws'); // npm install -g ws |
This file contains 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
// Simulate mdash.net device. To run this script, install ws library first: | |
// $ npm -g i ws | |
// $ node devsim.js MDASH_DEVICE_TOKEN | |
const Websocket = require('ws'); // npm install -g ws | |
const pass = process.argv[2]; // Device password | |
const addr = 'wss://mdash.net/api/v2/rpc?access_token=' + pass; | |
const ws = new Websocket(addr, {origin: addr}); | |
ws.on('error', msg => console.log(msg.toString())); |
This file contains 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
void setup() { | |
Serial.begin(115200); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
int character = Serial.read(); | |
if (character == '0') digitalWrite(LED_BUILTIN, LOW); // '0' switches LED off | |
if (character == '1') digitalWrite(LED_BUILTIN, HIGH); // '1' switches LED on |
This file contains 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
static int BAUD = 115200, RTS = -1, DTR = -1, ESP32_GPIO = 11, ESP32_RESETN = 12; | |
void setup() { | |
Serial.begin(baud); | |
Serial1.begin(baud); | |
pinMode(ESP32_GPIO0, OUTPUT); | |
pinMode(ESP32_RESETN, OUTPUT); | |
// Reset ESP32, put into upload mode | |
digitalWrite(ESP32_GPIO0, LOW); |
This file contains 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 WebSocket = require('ws'); // npm install -g ws | |
const server = new WebSocket.Server({port: 8000}, function() { | |
console.log('WS server started'); | |
}); | |
server.on('connection', function connection(ws, req) { | |
let i = 0; | |
ws.on('message', function incoming(message) { | |
console.log('received', message); | |
}); | |
console.log('connected', req.connection.remoteAddress); |
This file contains 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
char *read_file(const char *path) { | |
FILE *fp; | |
char *data = NULL; | |
if ((fp = fopen(path, "rb")) == NULL) { | |
} else if (fseek(fp, 0, SEEK_END) != 0) { | |
fclose(fp); | |
} else { | |
size_t size = ftell(fp); | |
data = (char *) malloc(size + 1); | |
if (data != NULL) { |
This file contains 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>hiii</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://unpkg.com/[email protected]/dist/css/bootstrap.min.css" /> | |
<script src="https://unpkg.com/[email protected]"></script> | |
<script src="https://unpkg.com/[email protected]"></script> |