Skip to content

Latest commit

 

History

History
148 lines (106 loc) · 6.36 KB

File metadata and controls

148 lines (106 loc) · 6.36 KB

AWARE: WiFi

Swift Package Manager compatible

This sensor allows us to handle WiFi conditions and events.

Requirements

iOS 13 or later

Installation

You can integrate this framework into your project via Swift Package Manager (SwiftPM).

SwiftPM

  1. Open Package Manager Windows

    • Open Xcode -> Select Menu Bar -> File -> App Package Dependencies...
  2. Find the package using the manager

    • Select Search Package URL and type git@github.com:awareframework/com.awareframework.ios.sensor.wifi.git
  3. Import the package into your target.

  4. Turn ON Access WiFi Information capability on the Xcode project

Public Functions

WifiSensor

  • init(config:WiFiSensor.Config?): Initializes the WiFi sensor with the optional configuration.
  • start(): Starts the WiFi sensor with the optional configuration.
  • stop(): Stops the service.

WifiSensor.Config

Class to hold the configuration of the sensor.

Fields

  • sensorObserver: WiFiObserver: Callback for live data updates.
  • scanIntervalSeconds: Double: Wi-Fi scan interval in seconds. (default = 60)
  • enabled: Bool: Sensor is enabled or not. (default = false)
  • debug: Bool: Enable/disable logging. (default = false)
  • label: String: Label for the data. (default = "")
  • deviceId: String: Id of the device that will be associated with the events and the sensor. (default = "")
  • dbEncryptionKey: String?: Encryption key for the database. (default = nil)
  • dbType: DatabaseType: Which db engine to use for saving data. (default = .none)
  • dbPath: String: Path of the database. (default = "aware_wifi")
  • dbHost: String?: Host for syncing the database. (default = nil)

Broadcasts

  • WiFiSensor.ACTION_AWARE_WIFI_CURRENT_AP: currently connected to this AP. In the extras, WiFiSensor.EXTRA_DATA includes the WiFiData in json string format.
  • WiFiSensor.ACTION_AWARE_WIFI_NEW_DEVICE: new WiFi AP device detected. In the extras, WiFiSensor.EXTRA_DATA includes the WiFiData in json string format.
  • WiFiSensor.ACTION_AWARE_WIFI_SCAN_STARTED: WiFi scan started
  • WiFiSensor.ACTION_AWARE_WIFI_SCAN_ENDED: WiFi scan ended.

Data Representations

WiFi Scan Data

Field Type Description
bssid String access point BSSID (MAC address)
ssid String access point network name
security String security mode of the access point
frequency Int frequency of the access point (MHz)
rssi Int received signal strength in dBm
deviceId String AWARE device UUID
label String Customizable label. Useful for data calibration or traceability
timestamp Int64 Unixtime milliseconds since 1970
timezone Int Timezone of the device
os String Operating system of the device (ex. ios)
jsonVersion Int JSON schema version

WiFi Device Data

Contains the current device's own WiFi connection info.

Field Type Description
macAddress String MAC address of the device's WiFi interface
bssid String BSSID of the connected access point
ssid String SSID of the connected access point
deviceId String AWARE device UUID
label String Customizable label. Useful for data calibration or traceability
timestamp Int64 Unixtime milliseconds since 1970
timezone Int Timezone of the device
os String Operating system of the device (ex. ios)
jsonVersion Int JSON schema version

Example Usage

let wifiSensor = WiFiSensor.init(WifiSensor.Config().apply { config in
    config.sensorObserver = Observer()
    config.scanIntervalSeconds = 60
    config.debug = true
    // more configuration ...
})
// To start the sensor
wifiSensor.start()

// To stop the sensor
wifiSensor.stop()
// Implement an interface of WifiObserver
class Observer:WiFiObserver {
    func onWiFiAPDetected(data: WiFiScanData) {
        // Your code here ..
    }

    func onWiFiDisabled() {
        // Your code here ..
    }

    func onWiFiScanStarted() {
        // Your code here ..
    }

    func onWiFiScanEnded() {
        // Your code here ..
    }
}

Related Links

Author

Yuuki Nishiyama (The University of Tokyo), nishiyama@csis.u-tokyo.ac.jp

License

Copyright (c) 2025 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.