Created
November 26, 2019 02:23
-
-
Save ordnungswidrig/4cec2ebcfed3182d7aafafc6e0c07273 to your computer and use it in GitHub Desktop.
clojurescript on esp32
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
clj -m cljs.main -O advanced -co '{:infer-externs true}' --output-to main.js | |
echo "Upload with" | |
echo "espruino main.js" | |
echo "Or use the Espruino web IDE" |
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
(ns m) | |
(def wifi (js/require "Wifi")) | |
(def http (js/require "http")) | |
(defn ^:export start-wifi [cb] | |
(.connect wifi "ssid" #js{"password" "12345679"}, cb)) | |
(def n (atom 0)) | |
(defn ^:export handle-request [^js req, ^js res] | |
(js/console.log "Got a request" req (swap! n inc)) | |
(.writeHead res 200) | |
(.end res (str "Hello Clojure!"))) | |
(defn ^:export start-server [] | |
(js/console.log "Starting server...") | |
(-> (.createServer http handle-request) (.listen 80)) | |
(js/console.log "Webserver Created on port 80")) | |
(defn ^:export on-wifi [error] | |
(.getStatus wifi (fn [s] (js/console.log "Wifi Status" s))) | |
(if error | |
(js/console.log "Could not connect to Wifi") | |
)) | |
(defn ^:export main [] | |
(js/console.log "Connecting to Wifi..."); | |
(start-wifi on-wifi) | |
(start-server)) | |
(main) |
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
> curl -i http://192.168.1.107 | |
HTTP/1.1 200 OK | |
Server: Espruino 2v04 | |
Connection: close | |
Hello Clojure!% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment