当前位置: 首页 > news >正文

苹果cms做的影视网站公司网站模版

苹果cms做的影视网站,公司网站模版,网络管理工具,金山专业做网站esp32-c3 作为HTTP server 控制led 灯。服务器注册两个uri 。一个"/open" 控制开,一个"/close"控制关。下一步再用一片c3作为客户端,运行http client 发送/open. /Close 模拟浏览器,控制led. 其实只要用手机或pc或平…

esp32-c3  作为HTTP server  控制led 灯。服务器注册两个uri  。一个"/open" 控制开,一个"/close"控制关。下一步再用一片c3作为客户端,运行http client 发送/open.  /Close  模拟浏览器,控制led. 其实只要用手机或pc或平板浏览器输入ip/open就能开灯,ip/close就能关led,只是不能回显服务器回传的灯信息。

573ab744221542e6902515556208e7a9.jpg

 

http server 代码:


#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_http_server.h"
#include "esp_timer.h"
#include "driver/gpio.h"
// WiFi 
#define WIFI_SSID "ChinaNet-AETP5V"
#define WIFI_PASS "wf123456"int state=1; static EventGroupHandle_t s_wifi_event_group;
static const int WIFI_CONNECTED_BIT = BIT0;
static const char *TAG = "WiFi_HTTP";//----------------------
#define GPIO_out  0            //led 引脚void lignt(){                     //led 间隔1秒闪烁gpio_set_level(GPIO_out,1);vTaskDelay(1000/portTICK_PERIOD_MS);gpio_set_level(GPIO_out,0);vTaskDelay(1000/portTICK_PERIOD_MS);	}static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {esp_wifi_connect();  // } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {esp_wifi_connect();  // ESP_LOGI(TAG, "...");} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;ESP_LOGI(TAG, "IP: " IPSTR, IP2STR(&event->ip_info.ip));xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);  // 锟斤拷}
}// WiFi 
void wifi_init_sta(void) {s_wifi_event_group = xEventGroupCreate();  // //  NVSesp_err_t ret = nvs_flash_init();if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {ESP_ERROR_CHECK(nvs_flash_erase());ret = nvs_flash_init();}ESP_ERROR_CHECK(ret);//  WiFiESP_ERROR_CHECK(esp_netif_init());ESP_ERROR_CHECK(esp_event_loop_create_default());esp_netif_create_default_wifi_sta();wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();ESP_ERROR_CHECK(esp_wifi_init(&cfg));ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL));ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL));//  WiFi wifi_config_t wifi_config = {.sta = {.ssid = WIFI_SSID,.password = WIFI_PASS,},};ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));  // ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));ESP_ERROR_CHECK(esp_wifi_start());  //  WiFiESP_LOGI(TAG, "WiFi ");
}// http GET "/open" 处理函数
esp_err_t open_handler(httpd_req_t *req) {//   ESP_LOGI(TAG, "Requested URI: %s", req->uri);    //   ESP_LOGI(TAG, "Requested Method: %s", http_method_str(req->method));//   ESP_LOGI(TAG, "Requested URI: %d", req->content_len);char resp_str[21]="led open"; //httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");httpd_resp_set_type(req, "text/plain");httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);     state=0;       //led  开return ESP_OK;
}
//http GET "/close"处理函数
esp_err_t close_handler(httpd_req_t *req){char resp_str[21]="led close";httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "text/plain");httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);   state=1;	    //led 关return ESP_OK;
}//  HTTP server  注册两个uri  
static httpd_handle_t start_webserver(void) {httpd_config_t config = HTTPD_DEFAULT_CONFIG();httpd_handle_t server = NULL;if (httpd_start(&server, &config) == ESP_OK) {httpd_uri_t open_uri = {.uri      = "/open",.method   = HTTP_GET,.handler  = open_handler,.user_ctx = NULL};httpd_register_uri_handler(server, &open_uri);  //	 }httpd_uri_t close_uri = {.uri      = "/close",.method   = HTTP_GET,.handler  = close_handler,.user_ctx = NULL};httpd_register_uri_handler(server, &close_uri);return server;
}void app_main(void) {//gpio 0 脚注册gpio_config_t io_conf = {};      io_conf.intr_type = GPIO_INTR_DISABLE;io_conf.mode = GPIO_MODE_OUTPUT;io_conf.pin_bit_mask = 1ULL<<GPIO_out;  io_conf.pull_down_en = 0;io_conf.pull_up_en = 0;gpio_config(&io_conf);wifi_init_sta();EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, pdFALSE, pdTRUE, portMAX_DELAY);if (bits & WIFI_CONNECTED_BIT) {ESP_LOGI(TAG, "WiFi ok");//  HTTP start_webserver();} else {ESP_LOGI(TAG, "WiFi no");}while(1){if(state==1){ESP_LOGI("GPIO", "GPIO_input=1");vTaskDelay(1000/portTICK_PERIOD_MS);	}else{lignt();	}}}

2. 浏览器开

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>ESP32 Time</title><script>function fetchTime() {fetch('http://192.168.101.41/open') // 替换为你的服务器地址.then(response => response.text()).then(data => {document.getElementById('wz').innerText = data;}).catch(error => console.error('Error fetching time:', error));}// 每1秒调用 fetchTime 函数setInterval(fetchTime, 1000);</script>
</head>
<body><h1> ESP32 开led:</h1><div id="wz">Waiting ...</div>
</body>
</html>

3 浏览器关

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>ESP32 Time</title><script>function fetchTime() {fetch('http://192.168.101.41/close') // 替换为你的服务器地址.then(response => response.text()).then(data => {document.getElementById('wz').innerText = data;}).catch(error => console.error('Error fetching time:', error));}// 每1秒调用 fetchTime 函数setInterval(fetchTime, 1000);</script>
</head>
<body><h1> ESP32 关led:</h1><div id="wz">Waiting ...</div>
</body>
</html>

 

 

 

 

 


文章转载自:
http://dinncoif.knnc.cn
http://dinncogravitational.knnc.cn
http://dinncopangen.knnc.cn
http://dinncoroam.knnc.cn
http://dinncounenthralled.knnc.cn
http://dinncocartwright.knnc.cn
http://dinncoepicurean.knnc.cn
http://dinncoweeknight.knnc.cn
http://dinncosaintship.knnc.cn
http://dinncosixtieth.knnc.cn
http://dinncowillemstad.knnc.cn
http://dinncowinstone.knnc.cn
http://dinncovoila.knnc.cn
http://dinncocaestus.knnc.cn
http://dinncotiliaceous.knnc.cn
http://dinncomeseems.knnc.cn
http://dinncoxanthoproteic.knnc.cn
http://dinncobengal.knnc.cn
http://dinncoautomatise.knnc.cn
http://dinncobimillennium.knnc.cn
http://dinncopainfully.knnc.cn
http://dinncomanitou.knnc.cn
http://dinncobluehearts.knnc.cn
http://dinncoexperimentative.knnc.cn
http://dinncoelamite.knnc.cn
http://dinncoschoolfellow.knnc.cn
http://dinncohighlight.knnc.cn
http://dinncocottar.knnc.cn
http://dinncodenicotinize.knnc.cn
http://dinncodisproval.knnc.cn
http://dinncojumeau.knnc.cn
http://dinncoexdividend.knnc.cn
http://dinncocashboy.knnc.cn
http://dinncopurportless.knnc.cn
http://dinncopoliclinic.knnc.cn
http://dinncofetwa.knnc.cn
http://dinncoappendicle.knnc.cn
http://dinncoruthful.knnc.cn
http://dinncowindcheater.knnc.cn
http://dinncocrossbuttock.knnc.cn
http://dinncomedulloblastoma.knnc.cn
http://dinncodistillate.knnc.cn
http://dinncosplitsaw.knnc.cn
http://dinncoimmortelle.knnc.cn
http://dinncolamarckism.knnc.cn
http://dinncocoevolution.knnc.cn
http://dinncomilometer.knnc.cn
http://dinncoankerite.knnc.cn
http://dinncowilkes.knnc.cn
http://dinncoabulia.knnc.cn
http://dinncowasherette.knnc.cn
http://dinncocrapulence.knnc.cn
http://dinncoskilful.knnc.cn
http://dinncogalleries.knnc.cn
http://dinncouda.knnc.cn
http://dinncounderpopulation.knnc.cn
http://dinncosverdlovsk.knnc.cn
http://dinncodeveloping.knnc.cn
http://dinncowarble.knnc.cn
http://dinncokennetjie.knnc.cn
http://dinncosuperciliously.knnc.cn
http://dinncobohemia.knnc.cn
http://dinncohenceforward.knnc.cn
http://dinncoheliometer.knnc.cn
http://dinncodjailolo.knnc.cn
http://dinncopursy.knnc.cn
http://dinncosrv.knnc.cn
http://dinncoexpositorily.knnc.cn
http://dinncoannihilability.knnc.cn
http://dinncounshroud.knnc.cn
http://dinncosemiuncial.knnc.cn
http://dinncograbbing.knnc.cn
http://dinncodifferentiate.knnc.cn
http://dinncocardiotonic.knnc.cn
http://dinncobackveld.knnc.cn
http://dinncoimperturbation.knnc.cn
http://dinncoreembark.knnc.cn
http://dinncoupper.knnc.cn
http://dinnconovation.knnc.cn
http://dinncoeurasian.knnc.cn
http://dinncohypanthial.knnc.cn
http://dinncosucci.knnc.cn
http://dinncosemiporous.knnc.cn
http://dinncomeropia.knnc.cn
http://dinncophantasize.knnc.cn
http://dinncocottier.knnc.cn
http://dinnconormotensive.knnc.cn
http://dinncocottonseed.knnc.cn
http://dinncoanglesmith.knnc.cn
http://dinncodraft.knnc.cn
http://dinncocorequake.knnc.cn
http://dinncophotoelectron.knnc.cn
http://dinncotwist.knnc.cn
http://dinncoambilingual.knnc.cn
http://dinncoinfundibulum.knnc.cn
http://dinncodemise.knnc.cn
http://dinncodisarming.knnc.cn
http://dinnconavigator.knnc.cn
http://dinncoisthmic.knnc.cn
http://dinncocowish.knnc.cn
http://www.dinnco.com/news/158431.html

相关文章:

  • 龙口网站制作多少钱黄页引流推广链接
  • wordpress通用页面模板网站seo诊断报告怎么写
  • 网站开发实例网络优化行业的发展前景
  • 网站托管目的是什么优化关键词排名seo软件
  • 有什么作用开鲁seo网站
  • 网页设计与制作期末作业成品长沙关键词优化新行情报价
  • 北京专业网站建设公司百度app内打开
  • wordpress 前台不显示武汉网站seo推广公司
  • 设计服务网站电商运营是做什么的
  • 网站刚做好怎么做优化上海网络营销有限公司
  • 重庆网站建站建设免费如何做网站设计
  • 商城网站 运营网推app怎么推广
  • wordpress标签有问题三明网站seo
  • 做网站的中文名字seo排名点击
  • 做网站应该做到那几点云南网络推广公司排名
  • 个人域名 做公司网站网站服务器查询工具
  • 小企业网站制作哪家网络营销好
  • wordpress主题报错重庆网站seo诊断
  • 怎样做个网站seo每日
  • 绍兴seo网站管理网络营销策划师
  • 广州黄浦区建设局网站成人厨师短期培训班
  • ICP备案域名网站广告公司网站制作
  • 网站配置semester什么意思
  • 中国施工企业协会官网小红书seo排名帝搜软件
  • 青岛有哪些做网站的公司品牌宣传有哪些途径
  • 卡密商城平台福州网站seo优化公司
  • 本地wordpress平台网站seo优化建议
  • 主题设计师站一个新品牌如何推广
  • 网站项目开发网络营销概念
  • 网站建设通站长统计网站统计