i have two short Code Snippets which just serve for testing communication over a TCP Socket.
In Dart i have the following Code which compiles just fine and succesfully sends the Command to the esp8266 connected to my arduino:
import 'dart:io';
void main() async {
Socket socket = await Socket.connect('192.168.2.123', 80);
String command = "<2,1,>";
socket.write(command);
print(socket.port);
await Future.delayed(Duration(seconds: 1));
socket.close();
}
In Flutter the following snippet bound to a on Pressed Method does not succesfully sned the command:
class _MyStartScreenState extends State<MyStartScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: FlatButton(
color: Colors.orange,
onPressed: _sendCommandToEsp,
child: Text("On/Off"),
)
),
);
}
void _sendCommandToEsp() async{
Socket socket = await Socket.connect('192.168.2.123', 80);
String command = "<2,1,>";
socket.write(command);
await Future.delayed(Duration(seconds: 1));
socket.close();
}
}
Is there anything obvious I am not getting? I cannot figure out why this is the case. Help would be much appreciated!