I found a solution:
Use a SetInterval and wait for the IP address to show up.
wifi.getIP(function(l,ip){console.log("IP= ",ip,"\n\r"+l);xIP=ip;});
id=setInterval(function () {
console.log("Hello World");
if(xIP!==undefined){
console.log("xIP= ",xIP);
clearInterval(id);
console.log("Wi-Fi Connected ");
// Now you can do something,
var client = require("net").connect({host: IP, port: 1234,protocolVersion: 17}, function() {
console.log('client connected');
client.write("Jello"+xIP);
client.on('data', function(data) {
console.log(">"+JSON.stringify(data)+"xjello");
client.write("Reply"+xIP);
});
client.on('end', function() {
console.log('client disconnected');
});
//client.end("UTLEY");
});
}
}, 1000);
And the output:
>echo(0);
Start
Start connection process
Try again
=undefined
Reset the ESP8266
Connecting to WiFi
OKxx1
OKxx2
IP= 192.168.1.3
null
Hello World
xIP= 192.168.1.3
Wi-Fi Connected
Client
client connected
Send 0 Jello192.168.1.3
>
And the Billy Bob device
>echo(0);
Start
Start connection process
Try again
=undefined
Reset the ESP8266
Connecting to WiFi
OKxx1
OKxx2
Wi-Fi Connected
Client
client connected
IP= 192.168.1.4
null
"192.168.1.4"
Send 0 XX 192.168.1.4Jello
>"Reply192.168.1.3"xjello
>
Disconnected
I expect to post the UDP in a few days after some code cleanup.
It modifies the ESP8266WiFi_0v25 module to allow UDP.
var wifi = require("UDP").connect(Serial, function(err) {
//var wifi = require("ESP8266WiFi_0v25").connect(Serial, function(err) {
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.
I found a solution:
Use a SetInterval and wait for the IP address to show up.
And the output:
And the Billy Bob device
I expect to post the UDP in a few days after some code cleanup.
It modifies the ESP8266WiFi_0v25 module to allow UDP.
var wifi = require("UDP").connect(Serial, function(err) {
//var wifi = require("ESP8266WiFi_0v25").connect(Serial, function(err) {