精华内容
下载资源
问答
  • 利用DHT111在PSOC3上实现温湿度测量,只用了一个管腿和LCD16X2模块就实现了
  • 实验4DHT112.rar

    2019-07-17 16:32:19
    STM32 的DTH111温湿度模块 能读取到温度和湿度,精确度还挺高
  • ESP32 and DHT22 low memory

    2020-12-02 02:08:24
    : 111.4, "temp": 45 } { "free": 1917, "usage": 383, "total": 2300, "history": 179, "gc": 0, "gctime": 1.989 } { "raw": "...
  • <img alt="untitled2" src="https://img-blog.csdnimg.cn/img_convert/cf8e56b11ce00affea4a4c7c111c786c.png" /> <p>Kind regards.</p><p>该提问来源于开源项目:BiglySoftware/BiglyBT</p></div>
  • 本设计是基于stc12单片机的温湿度检测系统,12单片机作为控制器,dht111模块采集温湿度信息,因为12单片机的系统时钟频率比51单片机要高,使用dht111时用示波器重新匹配时序,还是有问题,...
  • 树莓派4+DHT11温湿度模块通过MQTT发送温湿度数据(C语言) 前段时间在树莓派上做了一个用MQTT发送温湿度数据的小程序,参考了已有的博客,...·MQTT服务器IP地址为192.168.1.111(使用时记得改成自己的IP地址) ·使

    树莓派4+DHT11温湿度模块通过MQTT发送温湿度数据(C语言)

    前段时间在树莓派上做了一个用MQTT发送温湿度数据的小程序,参考了已有的博客,发现使用的语言全是python,然而项目要求必须用C语言,花了很久的时间,也学习了许多C语言的知识,现在把学习的过程记录一下,请有需要的同学自取~

    前期准备

    ·树莓派4
    ·DHT11温湿度传感器
    ·mosquitto(可参照树莓派安装mosquitto的博客)

    代码简要说明

    ·MQTT服务器IP地址为192.168.1.111(使用时记得改成自己的IP地址)
    ·使用gpio1口读取数据,下面是树莓派4的管脚图
    在这里插入图片描述
    ·主题为tempHumi
    ·每隔三秒发送一次

    代码部分

    #include <stdio.h>
    #include <stdlib.h>
    #include <wiringPi.h>
    #include <mosquitto.h>
    #include <string.h>
    typedef unsigned char uint8;
    typedef unsigned int  uint16;
    typedef unsigned long uint32;
    
    #define HIGH_TIME 32
    
    int pinNumber = 1;  //use gpio1 to read data
    uint32 databuf;
    #define HOST "192.168.1.111"
    #define PORT  1883
    #define KEEP_ALIVE 60
    #define MSG_MAX_SIZE  512
    #define TOPIC_NUM 1
    
    bool session = true;
    uint8 readSensorData(void)
    {
        uint8 crc; 
        uint8 i;
     
        pinMode(pinNumber,OUTPUT); // set mode to output
        digitalWrite(pinNumber, 1); // output a low level
        delayMicroseconds(4);
        digitalWrite(pinNumber, 0); // output a high level 
        delay(25);
        digitalWrite(pinNumber, 1); // output a low level
        delayMicroseconds(60); 
        pinMode(pinNumber, INPUT); // set mode to input
        pullUpDnControl(pinNumber,PUD_UP);
     
        if(digitalRead(pinNumber)==0) //SENSOR ANS
        {
            while(!digitalRead(pinNumber)); //wait to high
            delayMicroseconds(80);
            for(i=0;i<32;i++)
            {
              while(digitalRead(pinNumber)); //data clock start
              while(!digitalRead(pinNumber)); //data start
              delayMicroseconds(HIGH_TIME);
              databuf*=2;
              if(digitalRead(pinNumber)==1) //1
              {
                databuf++;
              }
            }
     
            for(i=0;i<8;i++)
            {
              while(digitalRead(pinNumber)); //data clock start
              while(!digitalRead(pinNumber)); //data start
              delayMicroseconds(HIGH_TIME);
              crc*=2;  
              if(digitalRead(pinNumber)==1) //1
              {
                crc++;
              }
            }
          return 1;
        }
        else
        {
          return 0;
        }
    }
    
    const static char* topic[TOPIC_NUM] =
    {
    	"tempHumi",
    };
    
    void my_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
    {
    	
        if(message->payloadlen){
            printf("%s %s", message->topic, (char *)message->payload);
        }else{
            printf("%s (null)\n", message->topic);
        }
        fflush(stdout);
    }
    
    void my_connect_callback(struct mosquitto *mosq, void *userdata, int result)
    {
        int i;
        if(!result){
            /* Subscribe to broker information topics on successful connect. */
            mosquitto_subscribe(mosq, NULL, "ycy ", 2);
        }else{
            fprintf(stderr, "Connect failed\n");
        }
    }
    
    void my_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos)
    {
        int i;
        printf("Subscribed (mid: %d): %d", mid, granted_qos[0]);
        for(i=1; i<qos_count; i++){
            printf(", %d", granted_qos[i]);
        }
        printf("\n");
    }
    
    void my_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str)
    {
        /* Pring all log messages regardless of level. */
        printf("%s\n", str);
    }
    
    int main()
    {
        struct mosquitto *mosq = NULL;
    	char buff[MSG_MAX_SIZE];
    	if (-1 == wiringPiSetup()) {
          //printf("Setup wiringPi failed!");
          return 1;
        }
        pinMode(pinNumber, OUTPUT); // set mode to output
        digitalWrite(pinNumber, 1); // output a high level 
        mosquitto_lib_init();
     
        mosq = mosquitto_new(NULL,session,NULL);
        if(!mosq){
            printf("create client failed..\n");
            mosquitto_lib_cleanup();
            return 1;
        }
    
        mosquitto_log_callback_set(mosq, my_log_callback);
        mosquitto_connect_callback_set(mosq, my_connect_callback);
        mosquitto_message_callback_set(mosq, my_message_callback);
        mosquitto_subscribe_callback_set(mosq, my_subscribe_callback);
    	
        if(mosquitto_connect(mosq, HOST, PORT, KEEP_ALIVE)){
            fprintf(stderr, "Unable to connect.\n");
            return 1;
        }
    
        int loop = mosquitto_loop_start(mosq); 
        if(loop != MOSQ_ERR_SUCCESS)
        {
            printf("mosquitto loop error\n");
            return 1;
        }
    
    	//while(fgets(buff, MSG_MAX_SIZE, stdin) != NULL)
    	while(1)
        {
    		pinMode(pinNumber,OUTPUT); // set mode to output
    		digitalWrite(pinNumber, 1); // output a high level 
    		
    		if(readSensorData())
    		{
    		  printf("OK!\n");
    		  printf("RH:%d.%d\n",(databuf>>24)&0xff,(databuf>>16)&0xff); 
    		  printf("TMP:%d.%d\n",(databuf>>8)&0xff,databuf&0xff);
    		 // databuf=0;
    		}
    		else
    		{
    		  printf("Error!\n");
    		}
    		sprintf(buff,"TMP:%d.%d,RH:%d.%d",(databuf>>8)&0xff,databuf&0xff,(databuf>>24)&0xff,(databuf>>16)&0xff);
      
            mosquitto_publish(mosq,NULL,"tempHumi",strlen(buff),buff,0,0);
            memset(buff,0,sizeof(buff));
    		delay(3000);		
        }
    
        mosquitto_destroy(mosq);
        mosquitto_lib_cleanup();
    
        return 0;
    }
    

    注:最后编译时,在终端输入编译指令记得加上-lmosquitto和-lwiringPi链接必要的库
    例:

    gcc test.c -o test.exe -lmosquitto -lwiringPi
    
    展开全文
  • 温湿度传感器DHT111 USB电源1 USB数据线1 杜邦线若干 Atom Shield扩展板可选 说明:Atom Shield扩展板是Atom的配套扩展板,其将5V电源管脚、3.3V电源管脚和GND管脚进行了扩充,其余IO管脚与Atom的管脚一一对应。为...
  • 2019-04-11 22:14:57.821 4649-4939/com.masterwok.demosimpletorrentandroid D/TorrentSession: Received alert: DHT_ANNOUNCE - dht_announce_alert - incoming dht announce: 213.254.111.41:32108 (c42e6bf2e...
  • 2018-09-18 03:56:36,948 ERROR lbrynet.dht.protocol:444: error handling request for 35.153.147.111:4444 b'store' Traceback (most recent call last): File "lbrynet\dht\protocol.py", line...
  • BTSync1.4电脑端+移动端

    2018-11-08 19:36:12
    BTSync_x64-1.4.111.exe和BTSync-1.4.65.apk(或BTSync-2.0.64.apk)为BTSync目前可用于连接同一DHT(如连接同一个路由器wifi)电脑端、手机端等多终端无线共享文件。 注意: 1.文件夹共享可设置共享时间限制:几天...
  • Initializing Ethernet

    2020-12-01 22:58:39
    { 11, 111, 111, 11}; // google will tell you: "public ip address" <p>void startEthernet(){ Serial.println("... Initializing ethernet"); if(Ethernet.begin(mac) == 0){ Serial...
  • IPv6 bugs

    2020-11-24 14:28:23
    (#111) I just quickly tried it out, and I came across the following problems (both were existed with the previosly mentioned patches): <p>A. Can't connect to udp trackers, error message: <code>...
  • ls many files case coredump

    2021-01-07 12:44:02
    #13 0x00007f7c834c40d9 in dht_readdirp_cbk (frame=frame=0x7f7bdc010e18, cookie=<optimized out>, this=<optimized out>, op_ret=<optimized out>, op_ret=17, op_...
  • PANIC in queryPeer

    2020-12-02 10:00:02
    May 09 18:27:19 ip-172-31-46-15 relay.sh[818]: /home/ubuntu/go/pkg/mod/github.com/jbenet/goprocess.1.2/impl-mutex.go:111 +0x1f7 </code></pre>该提问来源于开源项目:libp2p/go-libp2p-kad-dht...
  • 2020-10-05T05:10:46.111Z INFO index-miner module/onchain.go:36 updating on-chain index... 2020-10-05T05:10:46.114Z INFO reputation reputation/reputation.go:200 rebuilding index 2020-10-05T05:10:46.114...
  • 2017-09-20 13:25:13,111 INFO lbrynet.core.RateLimiter:72: Starting rate limiter. 2017-09-20 13:25:13,112 INFO lbrynet.core.BlobManager:42: Starting disk blob manager. blob_dir: /home/niko/.lbrynet/...
  • <div><p>I've been trying to run a test network from a single node, using a zero-state that I create using create-state. <p>I'...<p>The regular global config has about 111 entries; ...
  • 10锂电池充电板块1.111.1 11LCD-12864液晶屏块26.5126.5 12语音合成模块SYN6288块57157 13带外壳喇叭\0.5W\8欧个10110 14温湿度传感器DHT11块17117 15优力源14500锂电池个12.8338.4 958.02 工业粉尘远程监测系统软件...
  • /Users/erinswenson-healey/go/src/gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/impl-mutex.go:111 +0x1f5 stopping filecoin :( </code></pre> <h3>Where to Begin <p>If the ...
  • Lan Discovery segfault

    2020-12-01 16:56:06
    <div><p>When running $ cargo run --example dht_node</code></p> <pre><code> Starting program: /home/humbug/zetox/target/debug/examples/dht_node [Thread debugging using libthread_db enabled] Using host...
  • Help wanted...

    2020-12-09 02:54:54
    to talk, the DHT-11 to return data, the BME280 to return data(thanks to your library and example sketch), and all on Pro Mini knockoffs. My question is this. <p>How (or where) do I change the units ...
  • 0.23 Release

    2021-01-12 06:19:49
    /ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu /ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64 /ip4/178.62.158.247/tcp/4001/ipfs/...
  • 5.1.6 常见NAT穿越解决方案 111 5.2 P2P与IMS结合 112 5.2.1 什么是IMS 112 5.2.2 P2P与IMS的网络融合 112 5.3 VoIP通信基础 113 5.3.1 VoIP系统概念 113 5.3.2 H.323协议 115 5.3.3 SIP 115 5.3.4...
  • compile error in debug.ino

    2020-12-08 19:01:26
    111,7 @@ //#define DEBUG_TELNET_SUPPORT 0 //#define DEBUG_UDP_SUPPORT 1 //#define DEBUG_WEB_SUPPORT 0 -//#define DOMOTICZ_SUPPORT 0 +#define DOMOTICZ_SUPPORT 0 //#define ENCODER_...
  • /usr/bin/install -c -m 644 kademlia/announce_flags.hpp kademlia/dht_settings.hpp kademlia/dht_state.hpp kademlia/dht_storage.hpp kademlia/dht_tracker.hpp kademlia/dht_observer.hpp kademlia/direct_...
  • 5.1.6 常见NAT穿越解决方案 111 5.2 P2P与IMS结合 112 5.2.1 什么是IMS 112 5.2.2 P2P与IMS的网络融合 112 5.3 VoIP通信基础 113 5.3.1 VoIP系统概念 113 5.3.2 H.323协议 115 5.3.3 SIP 115 5.3.4 RTP 117...
  • at org.apache.cassandra.dht.RandomPartitioner$1.validate(RandomPartitioner.java:95) at org.apache.cassandra.config.DatabaseDescriptor.applyConfig(DatabaseDescriptor.java:440) at org.apache....
  • [01:17:48.111 UTC] src/core/core.cpp:415 : Debug: "Connecting to 144.76.60.215:33445 (sonOfRa)" [01:17:48.112 UTC] src/core/core.cpp:415 : Debug: "Connecting to 23.226.230.47:33445 (stal)&...
  • [2020-11-06 22:57:01.312541] E [MSGID: 113001] [posix-inode-fd-ops.c:3761:posix_getxattr] 0-conf-posix: getxattr failed on /mnt/data/gluster-bricks/conf/brick1/ (path: /): dht.subvol.status [Operation...
  • 111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"ptath","model":"raspberry pi zeroW","serialNo":"12345678"...

空空如也

空空如也

1 2
收藏数 38
精华内容 15
关键字:

dht111