Turns out the problem was not with the ESP01 or with Espruino, but with my malformed request :) The debugging methods from this thread made that clear (it showed a HTTP-400 header coming back).
For whoever finds it useful, this is how Espruino connects to Home Assistant:
var wifi = require("Wifi");
var entity = 'smoke_kitchen';
wifi.connect("SSID", {password:"PASS"}, function (e) {
if( ! e )
{
wifi.setHostname("SmokeAlarm-"+entity+"_"+getSerial() );
var http = require("http");
var data = JSON.stringify( {state:'on'} );
var options = {
host: 'HASS-HOST',
port: 8123,
path: '/api/states/input_boolean.' + entity,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
'x-ha-access': 'Token if needed',
},
};
var req = http.request( options, function (res) {
console.log('Status: ' + res.statusCode);
console.log( res );
});
req.write( data );
req.end();
} else
{
console.log("Error connecting to wifi: ", e );
}
});
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.
Turns out the problem was not with the ESP01 or with Espruino, but with my malformed request :) The debugging methods from this thread made that clear (it showed a HTTP-400 header coming back).
For whoever finds it useful, this is how Espruino connects to Home Assistant: