Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created November 26, 2019 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordnungswidrig/4cec2ebcfed3182d7aafafc6e0c07273 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/4cec2ebcfed3182d7aafafc6e0c07273 to your computer and use it in GitHub Desktop.
clojurescript on esp32
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"
(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)
> 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