|
@@ -1,5 +1,3 @@
|
|
|
-#include <unity.h>
|
|
|
-
|
|
|
#include <iostream>
|
|
|
#include <string>
|
|
|
#include <atomic>
|
|
@@ -8,6 +6,10 @@
|
|
|
#include <kbf.h>
|
|
|
#include <kbf/wifi.h>
|
|
|
#include <kbf/rtos.h>
|
|
|
+#include <kbf/http/client.h>
|
|
|
+#include <kbf/web_service.h>
|
|
|
+
|
|
|
+#include <unity.h>
|
|
|
|
|
|
using std::cout;
|
|
|
using std::endl;
|
|
@@ -263,7 +265,7 @@ void wifiScanSlave() {
|
|
|
|
|
|
TEST_CASE_MULTIPLE_DEVICES("WiFi scan", "[kbf_wifi]", wifiScanMaster, wifiScanSlave)
|
|
|
|
|
|
-kbf::rtos::EventGroup eventGroup;
|
|
|
+static kbf::rtos::EventGroup eventGroup;
|
|
|
|
|
|
void wifiIpMaster() {
|
|
|
using namespace kbf;
|
|
@@ -301,3 +303,83 @@ void wifiIpSlave() {
|
|
|
}
|
|
|
|
|
|
TEST_CASE_MULTIPLE_DEVICES("WiFi custom IP address", "[kbf_wifi]", wifiIpMaster, wifiIpSlave)
|
|
|
+
|
|
|
+static kbf::http::Client *client;
|
|
|
+
|
|
|
+void wifiModeSwitchMaster() {
|
|
|
+ using namespace kbf;
|
|
|
+ eventGroup = rtos::EventGroup();
|
|
|
+
|
|
|
+ auto ap = wifi::AP::create(
|
|
|
+ KBF_TEST_WIFI_DUAL_MASTER_SSID,
|
|
|
+ KBF_TEST_WIFI_PASS,
|
|
|
+ net::IP("192.168.1.1")
|
|
|
+ );
|
|
|
+ ap->onConnect = {[](wifi::AP::STA &) {
|
|
|
+ wifi::getSTA()->connect(KBF_TEST_WIFI_DUAL_SLAVE_SSID, KBF_TEST_WIFI_PASS);
|
|
|
+ }};
|
|
|
+
|
|
|
+ delete client;
|
|
|
+ client = new http::Client();
|
|
|
+
|
|
|
+ auto sta = wifi::STA::create();
|
|
|
+ sta->onIp = {[]() {
|
|
|
+ wifi::stopAP();
|
|
|
+ kbf::sleep(1000);
|
|
|
+ auto response = client->get("http://192.168.2.1/");
|
|
|
+ TEST_ASSERT_EQUAL(200, response->status);
|
|
|
+ eventGroup.setBit(0);
|
|
|
+ }};
|
|
|
+
|
|
|
+ wifi::start(ap, sta);
|
|
|
+ eventGroup.waitForBit(0);
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+class TestController : public kbf::WebService::Controller {
|
|
|
+public:
|
|
|
+ TestController() : kbf::WebService::Controller("/") {}
|
|
|
+
|
|
|
+ kbf::http::Response get(const kbf::http::Request &request) override {
|
|
|
+ eventGroup.setBit(0);
|
|
|
+ if (eventGroup.getBit(1)) return kbf::http::Response("", 501);
|
|
|
+ if (!eventGroup.getBit(2)) return kbf::http::Response("", 502);
|
|
|
+ return kbf::http::Response("", 200);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+void wifiModeSwitchSlave() {
|
|
|
+ using namespace kbf;
|
|
|
+ using namespace std;
|
|
|
+ eventGroup = rtos::EventGroup();
|
|
|
+
|
|
|
+ auto ap = wifi::AP::create(
|
|
|
+ KBF_TEST_WIFI_DUAL_SLAVE_SSID,
|
|
|
+ KBF_TEST_WIFI_PASS,
|
|
|
+ net::IP("192.168.2.1")
|
|
|
+ );
|
|
|
+ ap->onDisconnect = {[](wifi::AP::STA &) {
|
|
|
+ eventGroup.setBit(1);
|
|
|
+ }};
|
|
|
+
|
|
|
+ auto sta = wifi::STA::create();
|
|
|
+ sta->onReconnecting = {[](int, int) {
|
|
|
+ return false;
|
|
|
+ }};
|
|
|
+ sta->onDisconnect = {[]() {
|
|
|
+ eventGroup.setBit(2);
|
|
|
+ }};
|
|
|
+ wifi::start(ap, sta);
|
|
|
+
|
|
|
+ auto webService = WebService();
|
|
|
+ webService.attach<TestController>();
|
|
|
+ webService.start();
|
|
|
+
|
|
|
+ sta->connect(KBF_TEST_WIFI_DUAL_MASTER_SSID, KBF_TEST_WIFI_PASS);
|
|
|
+
|
|
|
+ eventGroup.waitForBit(0);
|
|
|
+ kbf::sleep(1000);
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE_MULTIPLE_DEVICES("WiFi mode switching", "[kbf_wifi]", wifiModeSwitchMaster, wifiModeSwitchSlave)
|