-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andy Liu <andy@madmachine.io>
- Loading branch information
Showing
11 changed files
with
171 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// swift-tools-version:5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
import PackageDescription | ||
let package = Package( | ||
name: "HttpPost", | ||
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(path: "../../.."), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.executableTarget( | ||
name: "HttpPost", | ||
dependencies: [ | ||
"SwiftIO", | ||
"MadBoards", | ||
// use specific library would speed up the compile procedure | ||
.product(name: "ESP32ATClient", package: "MadDrivers") | ||
]), | ||
] | ||
) |
50 changes: 50 additions & 0 deletions
50
Examples/ESP32ATClient/HttpPost/Sources/HttpPost/HttpPost.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import SwiftIO | ||
import MadBoard | ||
import ESP32ATClient | ||
|
||
@main | ||
public struct HttpPost { | ||
public static func main() { | ||
sleep(ms: 100) | ||
|
||
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. | ||
let wifiMode = try esp.getWiFiMode() | ||
print("ESP32 WiFi mode: \(wifiMode)") | ||
|
||
// Fill the SSID and password below. | ||
_ = try esp.joinAP(ssid: "", password: "", autoConnect: true) | ||
print("ESP32 WiFi status: \(esp.wifiStatus)") | ||
|
||
let ipInfo = try esp.getStationIP() | ||
print(ipInfo) | ||
|
||
} catch { | ||
print("Error: \(error)") | ||
} | ||
|
||
while true { | ||
if esp.wifiStatus == .ready { | ||
do { | ||
let ret = try esp.httpPost(url: "https://httpbin.org/post", headers: ["Accept: application/json"]) | ||
print(ret) | ||
} catch { | ||
print("Http POST Error: \(error)") | ||
} | ||
} else { | ||
_ = try? esp.readLine(timeout: 1000) | ||
print("WiFi status: \(esp.wifiStatus)") | ||
} | ||
|
||
sleep(ms: 1000) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
Examples/ESP32ATClient/JoinWiFi/Sources/JoinWiFi/JoinWiFi.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// Read temperature and relative humidity every second. | ||
import SwiftIO | ||
import MadBoard | ||
import ESP32ATClient | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// Read temperature and relative humidity every second. | ||
import SwiftIO | ||
import MadBoard | ||
import ESP32ATClient | ||
|
Oops, something went wrong.