OK I was trying to keep the example super simple which is why I wasn't responding to the incoming http requests.
Here is a more in-depth example that I can't get to work.
Flow should be like this:
Espruino takes the response from the internet resource and sends it back to the device that made the http request.
const wifi = require("EspruinoWiFi"); const http = require('http'); const startServer = () => { http.createServer(function (req, res) { console.log('got http request'); console.log(req); if (req.url === '/') { res.writeHead(200); getPage((data) => { console.log('got http response'); console.log(data); console.log('send http response back to requester'); res.end(data); }); } }).listen(80); console.log('http server started'); }; const getPage = (callback) => { console.log('get page'); http.get("http://www.pur3.co.uk/hello.txt", function(res) { let data = ''; console.log("Response: ", res); res.on('data', function(d) { data += d; }); res.on('end', () => { console.log('get request ended'); callback(data); }); }); }; wifi.connect('realAP', { password: 'realPW' }, (err) => { if (err) { throw err; } console.log('wifi connected'); wifi.startAP('ourAP', { password: 'ourPW', authMode: 'wpa2', }, (err) => { if (err) { throw err; } console.log('ap started'); startServer(); }); });
@dave_irvine started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
OK I was trying to keep the example super simple which is why I wasn't responding to the incoming http requests.
Here is a more in-depth example that I can't get to work.
Flow should be like this:
Espruino takes the response from the internet resource and sends it back to the device that made the http request.