Connect to embedded Printer in a PDA device - flutter

I am developing a flutter app to print receipt from a PDA device. The device is an Android 6.0 and has built in printer. I am trying to figure out how to connect to the printer to send printing command through esc_pos_printer https://pub.dev/packages/esc_pos_printer flutter package. However, what I found only through Network or Bluetooth.
const PaperSize paper = PaperSize.mm80;
final profile = await CapabilityProfile.load();
final printer = NetworkPrinter(paper, profile);
final PosPrintResult res = await printer.connect('192.168.0.123', port: 9100);
do you have any idea to connect to the printer

Related

Flutter setup MQTT with .p12 file

I am currently rebuilding an App using Flutter, in the old iOS and Android app, both would fetch the .p12 file from backend to setup the MQTT socket connection.
But the Flutter package I'm trying to use mqtt_client seems to require useCertificateChain, usePrivateKey and setClientAuthorities
three files like this:
SecurityContext context = new SecurityContext()
..useCertificateChain('path/to/my_cert.pem')
..usePrivateKey('path/to/my_key.pem', password: 'key_password')
..setClientAuthorities('path/to/client.crt', password: 'password');
client.secure = true;
client.securityContext = context;
Code from: https://emqx.medium.com/using-mqtt-in-the-flutter-project-6a5d90179c8b
I keep studying the mqtt_client package, but the examples and documents they provide don't seem to have the option to use .p12 file to establish socket connection.
If I have to download the .p12 file to mobile then extract and resave three files again, it would not make sense to use Flutter.
Is there any way I can use .p12 file in the mqtt_client package, or is there any other option or package can achieve this?
Thanks for helping!
I figured it out that I could insert the p12 file using client.connect, but the package document never said anything about this. This suppose to be a very common way to build MQTT connection.
_client = MqttServerClient.withPort(_host!, _identifier, _port);
_client?.keepAlivePeriod = 60;
_client?.logging(on: true);
_client?.setProtocolV311();
_client?.secure = true;
final securityContext = SecurityContext.defaultContext;
securityContext.setClientAuthorities('$_certPath/ios.p12', password: '');
securityContext.useCertificateChain('$_certPath/ios.p12', password: '');
securityContext.usePrivateKey('$_certPath/ios.p12', password: '');
_client?.securityContext = securityContext;

iOS 14 gives "OS Error: Bad file descriptor, errno = 9" when doing local network broadcasting

Doing a little Jeopardy style Q&A here.
I'm developing an app in Flutter that uses the udp package for broadcasting on the local network. This has worked fine on Android, Windows, macOS and iOS until I tried on an iOS 14.6 device.
The code flow is mainly like this:
var endPoint = Endpoint.broadcast(port: Port(6000));
var udpFuture = UDP.bind(Endpoint.any(port: Port(6000)));
udpFuture.then((udp) {
udp.listen((datagram) {
handleMessage(datagram.data);
});
udp.send(bytesToSend, endPoint);
}
The error message I'm getting is this: Unhandled Exception: OS Error: Bad file descriptor, errno = 9
Starting from iOS 14 your app needs the Multicast networking entitlement com.apple.developer.networking.multicast to be able to send or receive IP multicast traffic.
To get the entitlement you need to apply using Apple's request form. It took me 4-5 days before I got the request approved.
Then you can follow the instructions on Apple's forums to get up and running.

Issues with Flutter and Phoenix Channels

We're having some issues with our Flutter App and Pheonix Web Sockets. We know that the Backend is working properly, since the JavaScript client is fully functional. But with the Flutter app we can't connect to the server.
final socket = PhoenixSocket("ws://###.##/socket");
connectSocket() async {
await widget.socket.connect();
_channel = widget.socket.channel("test:lobby")
_channel.on("say", _say);
_channel.join();
}
One of the errors were gettig:
I/flutter ( 4227): WebSocket connection to ws://###.##:8080/socket?vsn=2.0.0 failed!: WebSocketException: Connection to 'http://###.##:8080/socket?vsn=2.0.0#' was not upgraded to websocket
On the client side we're using Phoenix Wings, the port and URL are correct.
Why does this keep happening?
Are there any other libraries for Flutter with Phoenix Interactions?
Is there a better documentation for phoenix_wings or for any other packages?
I had it working as
final socket = PhoenixSocket("ws://####.###/socket/websocket");
hth.

Connecting Raspberry Pi to Unity via Bluetooth

I want to connect my Raspberry Pi to unity via Bluetooth (I am writing an app that in the future will use the phone to connect to the Pi via Bluetooth).
How do I do that ? I was not able to find the answer on SO or anywhere else.
How do I transfer data via Bluetooth ?
How do I do that ? I was not able to find the answer on SO or anywhere else.
I googled it and found this
How do I transfer data via Bluetooth ?
This might help link
Or you could write a python script similar to this
# Uses Bluez for Linux
#
# sudo apt-get install bluez python-bluez
#
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/x232.html
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/c212.html
import bluetooth
def receiveMessages():
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
server_sock.bind(("",port))
server_sock.listen(1)
client_sock,address = server_sock.accept()
print "Accepted connection from " + str(address)
while True:
data = client_sock.recv(1024)
print "received [%s]" % data
#client_sock.close()
#server_sock.close()
def sendMessageTo(targetBluetoothMacAddress):
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((targetBluetoothMacAddress, port))
sock.send("hello!!")
sock.close()
def lookUpNearbyBluetoothDevices():
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
print str(bluetooth.lookup_name( bdaddr )) + " [" + str(bdaddr) + "]"
lookUpNearbyBluetoothDevices()
receiveMessages()
Code Description: It looks up for available Bluetooth devices and receives messages from the first Bluetooth device which initiates the connection. It sends messages to target Bluetooth device as per mac address specified in function arguments.
Reference: Link

How to check connection in Intel XDK

My app need to detect if the device is connected to the internet or not. To do this I'm using the below script:
document.addEventListener("intel.xdk.device.connection.update",function(){
if(intel.xdk.device.connection == "none")
{
alert("Offline");
} else {
alert("Online");
}
},false);
intel.xdk.device.updateConnection();
This code work perfectly in the emulator, but not in my Moto G, using Intel XDK Preview tool or after install the apk generated using Cordova!
Didn't show any fail message, just do nothing!
Once you added Cordova Network plugin, you can detect network details as:
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
Following links explain how to use Intel-xdk bridge to call different APIs
Intel XDK Cordova API Documentation
Intel XDK "legacy" API Documentation
Apache Cordova* API Documentation
https://software.intel.com/en-us/html5/xdkdocs#506911
Intel XDK Name Space API Plugin Details for Cordova Build Containers
Note that the APIs listed below augment the standard Cordova APIs, both APIs can and should be used in your application. In some cases there is overlap between the Cordova APIs and the intel.xdk APIs; in that case, we recommend you use the Cordova API first and then use the intel.xdk API when the Cordova API either does not provide the desired functionality or provides inadequate functionality.
Check this out, it will help you configure the plugin: Understanding the IntelĀ® XDK Cordova Build Options