Networking

RSS for tag

Explore the networking protocols and technologies used by the device to connect to Wi-Fi networks, Bluetooth devices, and cellular data services.

Networking Documentation

Post

Replies

Boosts

Views

Activity

CPU Saturation with Charts real time plotting from data received from Bluetooth
Hello everyone, I am new to Swift, it is my first project and I am a PhD Electrical Engineer student. I am designing an iOS app for a device that we are designing that is capable of reading electrical brain data and sending them via BLE with a sampling frequency of 2400 Hz. I created a Bluetooth service for the Swift app that every time it receives new data, processes it to split the different channels and add the new data to the Charts data arrays. Here is the code I've designed: func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { if characteristic.uuid == Nordic_UART_TX_CHAR_UUID { guard error == nil, let data = characteristic.value else { print("[Bluetooth] Error receiving data or no data: \(error?.localizedDescription ?? "Unknown Error")") return } DispatchQueue.global(qos: .background).async { self.processReceivedData(data) } } } func processReceivedData(_ data: Data) { var batch = [(Int, Int)]() for i in stride(from: 0, to: data.count - 4, by: 4) { let channel = Int(data[i] & 0xFF) let value = Int((Int(data[i + 3] & 0xFF) << 16) | (Int(data[i + 2] & 0xFF) << 8) | (Int(data[i + 1] & 0xFF))) - 8388608 batch.append((channel, value)) } DispatchQueue.main.async { for (channel, value) in batch { let nowTime = (Date().timeIntervalSince1970 - self.dataGraphService.startTime) let newDataPoint = DataGraphService.VoltagePerTime(time: nowTime, voltage: Double(value)/8388608, channel: "Channel \(channel - 15)") if channel == 16 { self.dataGraphService.lastX1 = nowTime self.dataGraphService.dataCh1.append(newDataPoint) } else if channel == 17 { self.dataGraphService.lastX2 = nowTime self.dataGraphService.dataCh2.append(newDataPoint) } else if channel == 18 { self.dataGraphService.lastX3 = nowTime self.dataGraphService.dataCh3.append(newDataPoint) } else if channel == 19 { self.dataGraphService.lastX4 = nowTime self.dataGraphService.dataCh4.append(newDataPoint) } } } } // DataGraphService.swift struct VoltagePerTime { var time: Double var voltage: Double var channel: String } @Published var dataCh1: [VoltagePerTime] = [] @Published var dataCh2: [VoltagePerTime] = [] @Published var dataCh3: [VoltagePerTime] = [] @Published var dataCh4: [VoltagePerTime] = [] @Published var windowSize: Double = 2.0 @Published var lastX1: Double = 0 @Published var lastX2: Double = 0 @Published var lastX3: Double = 0 @Published var lastX4: Double = 0 I also created a View that shows the real-time data from the different channels. ChartView( data: dataGraphService.dataCh1.filter { dataGraphService.getXAxisRange(for: dataGraphService.dataCh1, windowSize: dataGraphService.windowSize).contains($0.time) }, xAxisRange: dataGraphService.getXAxisRange(for: dataGraphService.dataCh1, windowSize: dataGraphService.windowSize), channel: "Channel 1", windowSize: dataGraphService.windowSize ) // ChartView.swift import SwiftUI import Charts struct ChartView: View { var data: [DataGraphService.VoltagePerTime] var xAxisRange: ClosedRange<Double> var channel: String var windowSize: Double var body: some View { RoundedRectangle(cornerRadius: 10) .fill(Color.gray.opacity(0.1)) .overlay( VStack{ Text("\(channel)") .foregroundColor(Color.gray) .font(.system(size: 16, weight: .semibold)) Chart(data, id: \.time) { item in LineMark( x: .value("Time [s]", item.time), y: .value("Voltage [V]", item.voltage) ) } .chartYAxisLabel(position: .leading) { Text("Voltage [V]") } .chartYScale(domain: [-1.6, 1.6]) .chartYAxis { AxisMarks(position: .leading, values: [-1.6, -0.8, 0, 0.8, 1.6]) AxisMarks(values: [-1.6, -1.2, -0.8, -0.4, 0, 0.4, 0.8, 1.2, 1.6]) { AxisGridLine() } } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Time [s]") } .chartXScale(domain: xAxisRange) .chartXAxis { AxisMarks(values: .automatic(desiredCount: Int(windowSize)*2)) AxisMarks(values: .automatic(desiredCount: 4*Int(windowSize)-2)) { AxisGridLine() } } .padding(5) } ) .padding(2.5) .padding([.leading, .trailing], 5) } } With these code I can receive and plot the data in real-time but after some time the CPU of the iPhone gets saturated and the app stop working. I have the guess that the code is designed in a way that the functions are called one inside the other one in a very fast speed that the CPU cannot handle. My doubt is if there is any other way to code this real-time plotting actions without make the iPhone's CPU power hungry. Thank you very much for your help!
1
1
567
Jan ’24
is it possible to operate `NEDNSProxyProvider` transparent mode
My macOS application utilizing NEDNSProxyProvider. i have a requirement to intercept only DNS requests of a certain query type, while others are expected to continue to their respective origin. For TCP there are two kinds of extensions NEAppProxyProvider and NETransparentProxyProvider. The latter is capable of returning NO from handleNewFlow causing the flow to proceed to communicate directly with the flow’s ultimate destination, instead of closing the flow. Is there a way to configure NEDNSProxyProvider to work in transparent mode for letting the flow to proceed to communicate directly? Current NEDNSProxyProvider limitation of dropping the connection when NO is returned requies me to open new socket and proxy the requests which causes noticable performance degradation under load.
2
0
499
Jan ’24
Bluetooth conflicting with Timer?
Hello everyone, Like so many others, I am a very newbie App developer. To my own detriment, I acknowledge I am trying to shortcut things a bit by using and modifying other pieces of code. Always easier to modify something that is already working, rather than staring at a blank screen not knowing how to begin. So this leads me to this problem I am having. This is a Bluetooth application. And the Bluetooth runs just fine in both of my views. However, when the Bluetooth is linked and active, and I am receiving data, a Timer will not run. As soon as I stop the Bluetooth source (using an Arduino nano), the time begins to count again. There are no errors flagged in Xcode, just does not work properly. I was hoping someone could take a look and find the issue, and let me know how to fix it. Hopefully it is something easy, but without any errors being thrown, hard to know what to look for. Thanks... So this is my Bluetooth Code: import Foundation import CoreBluetooth enum ConnectionStatus: String { case connected case disconnected case scanning case connecting case error } let BarrelBaristaService: CBUUID = CBUUID(string: "4FAFC201-1FB5-459E-8FCC-C5C9C331914B") //Temperature F let TemperatureCharacteristic: CBUUID = CBUUID(string: "5D54D470-8B08-4368-9E8F-03191A0314A5") //Humidity % let HumidityCharacteristic: CBUUID = CBUUID(string: "B2F5E988-C50F-4200-A1D9-5884F9417DEF") //Weight % let WeightCharacteristic: CBUUID = CBUUID(string: "BEB5483E-36E1-4688-B7F5-EA07361B26A8") class BluetoothService: NSObject, ObservableObject { private var centralManager: CBCentralManager! var BarrelBarristaPeripheral: CBPeripheral? @Published var peripheralStatus: ConnectionStatus = .disconnected @Published var TempValue: Float = 0 @Published var HumidValue: Float = 0 @Published var WeightValue: Float = 0 @Published var Connected: Bool = false override init() { super.init() centralManager = CBCentralManager(delegate: self, queue: nil) } func scanForPeripherals() { peripheralStatus = .scanning centralManager.scanForPeripherals(withServices: nil) } } extension BluetoothService: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { if central.state == .poweredOn { print("CB Powered On") scanForPeripherals() } } func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { if peripheral.name == "Barrel Barista" { print("Discovered \(peripheral.name ?? "no name")") BarrelBarristaPeripheral = peripheral centralManager.connect(BarrelBarristaPeripheral!) peripheralStatus = .connecting } } func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { peripheralStatus = .connected Connected = true peripheral.delegate = self peripheral.discoverServices([BarrelBaristaService]) centralManager.stopScan() } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { peripheralStatus = .disconnected Connected = false } func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) { peripheralStatus = .error print(error?.localizedDescription ?? "no error") } } extension BluetoothService: CBPeripheralDelegate { func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { for service in peripheral.services ?? [] { if service.uuid == BarrelBaristaService { print("found service for \(BarrelBaristaService)") peripheral.discoverCharacteristics([TemperatureCharacteristic], for: service) peripheral.discoverCharacteristics([HumidityCharacteristic], for: service) peripheral.discoverCharacteristics([WeightCharacteristic], for: service) } } } func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { for characteristic in service.characteristics ?? [] { peripheral.setNotifyValue(true, for: characteristic) print("found characteristic, waiting on values.") } } func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { if characteristic.uuid == TemperatureCharacteristic { guard let data = characteristic.value else { print("No data received for \(characteristic.uuid.uuidString)") return } let TempData: Float = data.withUnsafeBytes { $0.pointee } TempValue = TempData } if characteristic.uuid == HumidityCharacteristic { guard let data = characteristic.value else { print("No data received for \(characteristic.uuid.uuidString)") return } let HumidData: Float = data.withUnsafeBytes { $0.pointee } HumidValue = HumidData } if characteristic.uuid == WeightCharacteristic { guard let data = characteristic.value else { print("No data received for \(characteristic.uuid.uuidString)") return } let WeightData: Float = data.withUnsafeBytes { $0.pointee } WeightValue = WeightData } } }
0
0
388
Jan ’24
Find My - Bluetooth Trackers = AirTags?
Hey, I've been trying to find information but haven't had any luck so far. I own two third party bluetooth trackers (not AirTags), which I've linked to Find My. Recently, I misplaced an item that had one of these trackers attached. Surprisingly, even though I was quite far away, I was still receiving updates on its location a couple hours after I lost it. I'm curious to know, does connecting a third party bluetooth tracker to Find My function in the same way as AirTags? Are there any specific documents or resources where I can learn more about this? I'm really interested in understanding how it works.
1
0
632
Jan ’24
How to install dualpi2 qdisc on the rpi (router) to simulate congestion to test L4S
https://github.com/L4STeam/linux/ I tried installing the qdisc dualpi2 from the above link following the steps given in the Readme file onto the Raspberry pi 4 B At first I get the error: Couldn't find DTB bcm2711-rpi-4-b.dtb on the following paths: /etc/flash-kernel/dtbs /usr/lib/linux-image-5.15.72+ /lib/firmware/5.15.72+/device-tree/ I copied the file generated in the arch folder to the following locations, and run make modules_install make install For make install, i get "out of memory" error I tried following the steps mentioned below cd ~ mkdir initramfs cd initramfs sudo cp -a /boot . cd boot sudo update-initramfs -ut -b . sudo cp -a * /boot sudo apt-get autoremove Step 6 gives out of memory error. How do I fix the same?
0
0
326
Jan ’24
Compatibility of Low-Level Socket APIs with Mapped IPv6 Addresses
I am currently working on an application that communicates with an IPv4 node in an IPv6-only network. During DNS resolution for the server node on JIO and T-Mobile networks, I am receiving IPv4 and mapped IPv6 addresses. In my application, I am using these mapped IPv6 addresses in two different contexts: For high-level API calls on the app side, I am using URLSession API (in either Objective-C or Swift). For another target(c/c++), I am making low-level socket API calls(bind etc). These calls use the address passed from the app layer. As node is resolved to IPV4 and mapped IPv6 addresses My question is: Are low-level Socket APIs(bind etc) compatible with these mapped IPv6 addresses (example 64:ff9b::103.135.122.10)? Mapped IPv6 with Well know perfix(64:ff9b) Please provide the document/rfc reference for the same. Any guidance or resources on this topic would be greatly appreciated.
3
1
468
Jan ’24
Monitoring for network changes while backgrounded or suspended
Detecting New WiFi Connection + WiFi Details What I want to accomplish: The app, including when backgrounded or suspended, creates a local notification (assuming the app has permission for notifications) when there is a new WiFi network being used and ideally being able to execute some small code to customize the notification. This code would also have access to SSID info, security type, etc., so the sort of info in NEHotspotNetwork. A number of apps seem able to do this but I am having trouble replicating what they are doing. What I’ve looked at or tried: Looking at “TN3111: iOS Wi-Fi API overview” https://developer.apple.com/documentation/technotes/tn3111-ios-wifi-api-overview Navigate an internet hotspot (NEHotspotHelper) Doesn’t look like NEHotspotHelper would provide the above functionality for detecting changes while backgrounded and it seems to indicate that the special entitlement com.apple.developer.networking.HotspotHelper would not be granted for this use case anyway. Add an accessory to the user’s network (Wireless Accessory Configuration (WAC) or HomeKit) Doesn’t seem relevant to my use case Peer-to-peer networking Doesn’t seem relevant to my use case Location tracking I don’t want to know my user’s location and Lookout and Norton 360 (just two of many examples) don’t request or have location permissions (or request any permissions for that matter except notifications) and are still able to obtain the WiFi network info without it as well as detect changes in the background. Current Wi-Fi network NEHotspotNetwork .fetchCurrent(completionHandler:) So this is the most obvious since it returns the info I want but it requires the following permissions or configurations that neither Lookout or Norton 360 are requesting and also I don’t see how this API would trigger a backgrounded app to run, more for when your app is in the foreground and able to run already. From Apple docs: “This method produces a non-nil NEHotspotNetwork object only when the current network environment meets all four of the following critieria: The app is using the Core Location API and has user’s authorization to access precise location. The app used the NEHotspotConfiguration API to configure the current Wi-Fi network. The app has active VPN configurations installed. The app has an active NEDNSSettingsManager configuration installed. This method also requires the app to have the Access Wi-Fi Information Entitlement, and produces nil if the app lacks this entitlement.” Once again, apps that are able to do what I want don't seem to have location permissions, no VPN profile, no DNS config, no hotspot config.... Additional things I’ve considered that are not mentioned in the above: Using NWPathMonitor works for identifying a change, doesn’t trigger when app backgrounded and no access to SSID or other WiFi info. What am I missing? Is there some API that I totally missed? Thank you! Colin
1
0
1.1k
Jan ’24
Supervise device without erasing data?
Hello! I made an iOS app for a research study that blocks network connections with certain websites. I need to block around 2000 web domains. To achieve this, I had two options: Use Screentime API Use Network Extension Screentime API has a limitation that limits the number of websites it can block to 50 (https://developer.apple.com/documentation/managedsettings/webcontentsettings/blockedbyfilter-swift.property). The Network Extension on the other hand requires my device to be in supervised mode, which as I understand it, involves erasing the data on the phone and resetting it. Hence, I am here to ask if there is a way to do this without erasing user data when setting the device into supervised mode. Also, I am open to hearing any other alternatives I could pursue. Thanks!!
2
0
750
Feb ’24
Peer-to-Peer communications on devices on different networks
I am struggling to sort through the options for building an application that can send and receive messages peer-to-peer to any device connected to any network anywhere in the world. I know I will likely need a relay server to handle DNS and I will also need to handle changing IP addresses as mobile devices move around and their IP address changes. What I am puzzled about is I've read up on Bonjour and on the Network framework and it appears to me (and I may be wrong) that these capabilities only support either devices on the same local network, or devices that are in close proximity to one another. For an iOS application, what is the recommended service or framework to use to build the send/receive functionality in the app? Is it even possible? Thanks!
1
0
392
Feb ’24
BSD Sockets APIs compatibility with IPv4-mapped IPv6 addresses
I'm interested in whether SOCKET APIS like bind, accept, and connect can seamlessly work with a mapped IPv6 address like 64:ff9b::103.135.122.10 or any other IPv4-mapped IPv6 addresses? I've consulted the following thread for reference and it is stated: We do not support under-the-sockets bump-in-API (RFC 3338) and we do not support 464XLAT... https://developer.apple.com/forums/thread/5643. If it can support, what is above thread about?
1
0
385
Feb ’24
Apple devices can't ping each other in local network
Hi, I have a strange problem. In my local network, I have some apple devices (including mac, iphone, ipad) and a windows computer. The windows pc and any of the apple devices can ping each other, while every two of the apple devices can't ping each other. Whether udp or tcp are in the same situation. As is the situation, the firewall/mask/local ip are not the problems. I can't use wireshark to debug, because there is not any packet between these apple devices. Does someone know what the problem it may be? Or could someone tell me how to debug this? Thanks in advance!
2
0
1.2k
Feb ’24
Network extension process not getting auto launch after installation
I have a Network extension contains App Proxy and Content Filter. After installation, extension process is not getting auto launch. We want to execute some code in main.swift. extension process is getting launch on enabling either App Proxy or Content Filter. how to launch network extension process after installation? Installations Sample code: let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: id, queue: .main) OSSystemExtensionManager.shared.submitRequest(activationRequest)
3
0
723
Feb ’24
NSURLErrorDomain Code=-1009
I developed a iOS App, this App need to visit a local url. It can visit the url on iPhone 13 (iOS 15.4) and iPhone 14 Plus (iOS 16.5.1), but it can not visit the same url on iPhone 6s(iOS 15.8.1). The error message is 'NSURLErrorDomain Code=-1009'. 1). The url can be visited by Safari on iPhone 6s, so the network of iPhone 6s is fine. 2). The Local Network has enabled in the APP settings. 3). I notice that in iPhone Settings -> WLAN -> Apps Using WLAN & Cellular, my App information can be found on iPhone 13 and iPhone 14 Plus, and can not find my App information on iPhone 6s. How should I troubleshoot this issue? Thanks you! Follows are full error message. 2024-02-08 17:49:39.706240+0800 AstroeyeWiFi[1186:114419] Task .<8> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280715c20 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Denied over Wi-Fi interface), interface: en0, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<8>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<8>" ), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.0.1:50628/form/getDeviceId, NSErrorFailingURLKey=http://192.168.0.1:50628/form/getDeviceId, _kCFStreamErrorDomainKey=1} [DNO][getDeviceSysId][Error] underlying(Alamofire.AFError.sessionTaskFailed(error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280715c20 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_NSURLErrorNWPathKey=unsatisfied (Denied over Wi-Fi interface), interface: en0, _kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<8>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<8>" ), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.0.1:50628/form/getDeviceId, NSErrorFailingURLKey=http://192.168.0.1:50628/form/getDeviceId, _kCFStreamErrorDomainKey=1}), nil)
6
0
1.6k
Feb ’24
How to detect wifi network change in iOS when app is in background
0 How to detect wifi network change in iOS when the app is in background and suspended states? I want the iOS app to be notified whenever there is a change in network. For eg: I want the app to be notified when the device switches from WiFi-1 to WiFi-2. The app will be published on App Store. I tried using Hotspot Helper for this. It works perfectly. But in order to use Hotspot Helper we need to get an entitlement from Apple. Apple provides that entitlement only if we are creating hotspots which is not in our case. So, we cannot use Hotspot Helper.
2
0
1.1k
Feb ’24
TLS configuration in iOS 17.4 version, wcf service does not connect
Hello, I am currently receiving an error message when trying to connect to my web service(use http), I suspect it is a tsl configuration, I have already modified the Info.plist configuration file, currently I have this configuration: The error message is the following: System.InvalidOperationException: Not supported Content-Type in the response: " at System.Web.Services.Protocols.-WebServiceHelper.InvalidOperation (System. String , System.Net.WebResponse, System.Text.Encoding ) &lt;0x102261ef0 0x0014c&gt; in &lt;aleab3d663f2403-f86390ab4e99d1c4e#e4af9bbaef9-b71791783b4e0b13b9986&gt;:0 at System.Web.Services. Protocols.-SoapHttpClientProtocol.ReceiveRes- ponse (System. Net.WebResponse, System.Web.Services.Protocols.Soap-ClientMessage , System.Web.Services.Protocols.Soap- Extension [] ) &lt;0x10225d920 + Ox001ef&gt; in &lt;aleab3d663f2403-f86390ab4e99d1c4e#e4af9bbaef9-b71791783b4e0b1369986&gt;:0 at System.Web.Services.Protocols.-SoapHttpClientProtocol.AsyncGetRes- ponseDone (System.lAsyncResult) &lt;0x10225d300 + 0x0021f&gt; in &lt;aleab3d663f2403f86390ab4e99d1-c4e#e4af9bbaef9b71791783b4e0b13-b9986&gt;:0 ok Please help, someone has already had a similar problem, currently due to this problem you cannot log in to the application, greetings and thank you for your help.
1
0
453
Feb ’24