From 1cd75b3cf2f84e19cff38f8091607a77cd15f789 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 26 Sep 2024 11:42:52 +0800 Subject: [PATCH] Update for Embedded Swift(Remove swift-extra-json dependenci) Signed-off-by: Andy Liu --- .../11WiFi/Weather/.gitignore | 8 -- .../11WiFi/Weather/Package.mmp | 17 --- .../11WiFi/Weather/Package.swift | 28 ---- .../11WiFi/Weather/Sources/WeatherInfo.swift | 124 ------------------ .../11WiFi/Weather/Sources/main.swift | 60 --------- 5 files changed, 237 deletions(-) delete mode 100644 Examples/SwiftIOPlayground/11WiFi/Weather/.gitignore delete mode 100644 Examples/SwiftIOPlayground/11WiFi/Weather/Package.mmp delete mode 100644 Examples/SwiftIOPlayground/11WiFi/Weather/Package.swift delete mode 100644 Examples/SwiftIOPlayground/11WiFi/Weather/Sources/WeatherInfo.swift delete mode 100644 Examples/SwiftIOPlayground/11WiFi/Weather/Sources/main.swift diff --git a/Examples/SwiftIOPlayground/11WiFi/Weather/.gitignore b/Examples/SwiftIOPlayground/11WiFi/Weather/.gitignore deleted file mode 100644 index 0023a53..0000000 --- a/Examples/SwiftIOPlayground/11WiFi/Weather/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/SwiftIOPlayground/11WiFi/Weather/Package.mmp b/Examples/SwiftIOPlayground/11WiFi/Weather/Package.mmp deleted file mode 100644 index 102d0e2..0000000 --- a/Examples/SwiftIOPlayground/11WiFi/Weather/Package.mmp +++ /dev/null @@ -1,17 +0,0 @@ -# This is a MadMachine project file in TOML format -# This file holds those parameters that could not be managed by SwiftPM -# Edit this file would change the behavior of the building/downloading procedure -# Those project files in the dependent libraries would be IGNORED - -# Specify the board name below -# There are "SwiftIOBoard" and "SwiftIOMicro" now -board = "SwiftIOMicro" - -# Specifiy the target triple below -# There are "thumbv7em-unknown-none-eabi" and "thumbv7em-unknown-none-eabihf" now -# If your code use significant floating-point calculation, -# plz set it to "thumbv7em-unknown-none-eabihf" -triple = "thumbv7em-unknown-none-eabi" - -# Reserved for future use -version = 1 diff --git a/Examples/SwiftIOPlayground/11WiFi/Weather/Package.swift b/Examples/SwiftIOPlayground/11WiFi/Weather/Package.swift deleted file mode 100644 index 60f08a2..0000000 --- a/Examples/SwiftIOPlayground/11WiFi/Weather/Package.swift +++ /dev/null @@ -1,28 +0,0 @@ -// swift-tools-version: 5.9 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "Weather", - dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"), - .package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"), - .package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"), - .package(url: "https://github.com/swift-extras/swift-extras-json.git", branch: "main"), - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .executableTarget( - name: "Weather", - dependencies: [ - "SwiftIO", - "MadBoards", - // Use specific library name rather than "MadDrivers" would speed up the build procedure. - .product(name: "ESP32ATClient", package: "MadDrivers"), - .product(name: "ExtrasJSON", package: "swift-extras-json"), - ]), - ] -) diff --git a/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/WeatherInfo.swift b/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/WeatherInfo.swift deleted file mode 100644 index 9d4c498..0000000 --- a/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/WeatherInfo.swift +++ /dev/null @@ -1,124 +0,0 @@ -// Structs used to decode the JSON data from the weather service. -struct Coordinate: Decodable { - let longitude: Float - let latitude: Float - - enum CodingKeys: String, CodingKey { - case longitude = "lon" - case latitude = "lat" - } -} - -struct WeatherConditions: Decodable { - let id: Int - let main: String - let description: String - let icon: String -} - -struct MainInfo: Decodable { - let temp: Float - let feelsLikeTemp: Float - let minTemp: Float - let maxTemp: Float - let pressure: Int - let humidity: Int - let seaLevel: Int - let groundLevel: Int - - enum CodingKeys: String, CodingKey { - case temp - case feelsLikeTemp = "feels_like" - case minTemp = "temp_min" - case maxTemp = "temp_max" - case pressure - case humidity - case seaLevel = "sea_level" - case groundLevel = "grnd_level" - } -} - -struct Wind: Decodable { - let speed: Float - let degree: Int - let gust: Float - - enum CodingKeys: String, CodingKey { - case speed - case degree = "deg" - case gust - } -} - -struct Clouds: Decodable { - let cloudiness: Int - - enum CodingKeys: String, CodingKey { - case cloudiness = "all" - } -} - -struct Rain: Decodable { - let rain1h: Float? - let rain3h: Float? - - enum CodingKeys: String, CodingKey { - case rain1h = "1h" - case rain3h = "3h" - } -} - -struct Snow: Decodable { - let snow1h: Float? - let snow3h: Float? - - enum CodingKeys: String, CodingKey { - case snow1h = "1h" - case snow3h = "3h" - } -} - -struct Sys: Decodable { - let type: Int? - let id: Int? - let country: String - let sunrise: Int - let sunset: Int -} - -struct WeatherInfo: Decodable { - let coordinate: Coordinate - let weatherConditions: [WeatherConditions] - let base: String - let mainInfo: MainInfo - let visibility: Int - let wind: Wind - let clouds: Clouds - let rain: Rain? - let snow: Snow? - let dt: Int - let sys: Sys - let timezone: Float - let cityId: Int - let cityName: String - let cod: Int - - - enum CodingKeys: String, CodingKey { - case coordinate = "coord" - case weatherConditions = "weather" - case base - case mainInfo = "main" - case visibility - case wind - case clouds - case rain - case snow - case dt - case sys - case timezone - case cityId = "id" - case cityName = "name" - case cod - } -} \ No newline at end of file diff --git a/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/main.swift b/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/main.swift deleted file mode 100644 index 05db4e6..0000000 --- a/Examples/SwiftIOPlayground/11WiFi/Weather/Sources/main.swift +++ /dev/null @@ -1,60 +0,0 @@ -import SwiftIO -import MadBoard -import ESP32ATClient -import ExtrasJSON - -let rst = DigitalOut(Id.D24, value: true) -let uart = UART(Id.UART1, baudRate: 115200) -let esp = ESP32ATClient(uart: uart, rst: rst) - -do { - // If reset failed, you might need to adjust the baudrate. - try esp.reset() - print("ESP32 status: \(esp.esp32Status)") - - // Only in 'Station' or 'Station+SoftAP' mode can a connection to an AP be established. - var wifiMode = ESP32ATClient.WiFiMode.station - _ = try esp.setWiFiMode(wifiMode) - - // Print current Wi-Fi mode. - wifiMode = try esp.getWiFiMode() - print("ESP32 WiFi mode: \(wifiMode)") - - // Fill the SSID and password below. - try esp.joinAP(ssid: "", password: "", timeout: 20000) - print("ESP32 WiFi status: \(esp.wifiStatus)") - - // Print the assigned IP address. - let ipInfo = try esp.getStationIP() - print(ipInfo) -} catch { - print("Error: \(error)") -} - -sleep(ms: 1000) - -if esp.wifiStatus == .ready { - do { - // Send request to the weather service to obtain current weather. - // Update the URL with your API key and your city name. - let response = try esp.httpGet(url: "https://api.openweathermap.org/data/2.5/weather?q=metric&q=YourCity&appid=YourAPIKey", timeout: 30000) - - // Decode the JSON data and print the weather info. - let weatherInfo = try XJSONDecoder().decode(WeatherInfo.self, from: Array(response.utf8)) - print("City: \(weatherInfo.cityName)") - print("Weather: \(weatherInfo.weatherConditions[0].main)") - print("Temp: \(weatherInfo.mainInfo.temp)C") - print("Humidity: \(weatherInfo.mainInfo.humidity)") - } catch let error as DecodingError { - print("JSON Decoding Error: \(error)") - } catch { - print("Http GET Error: \(error)") - } -} else { - _ = try? esp.readLine(timeout: 1000) - print("WiFi status: \(esp.wifiStatus)") -} - -while true { - sleep(ms: 1000) -} \ No newline at end of file