c – 如何从Arduino库中读取数组?
发布时间:2020-12-16 07:21:03 所属栏目:百科 来源:网络整理
导读:我使用以太网模块使用 Cayenne-Arduino-Library和 arduino_uip将数据上传到服务器.我想从 CayenneEthernet.h读取myip [] 原版的: // DHCP with domainvoid begin(const char* auth,const char* domain = BLYNK_DEFAULT_DOMAIN,uint16_t port = BLYNK_DEFAUL
我使用以太网模块使用
Cayenne-Arduino-Library和
arduino_uip将数据上传到服务器.我想从
CayenneEthernet.h读取myip []
原版的: // DHCP with domain void begin(const char* auth,const char* domain = BLYNK_DEFAULT_DOMAIN,uint16_t port = BLYNK_DEFAULT_PORT,const byte mac[] = _blynkEthernetMac) { BLYNK_LOG("Here we are");// I added this to find this function. ... IPAddress myip = Ethernet.localIP(); BLYNK_LOG("My IP: %d.%d.%d.%d",myip[0],myip[1],myip[2],myip[3]); } 编辑: // DHCP with domain int* begin(const char* auth,const byte mac[] = _blynkEthernetMac) { ... IPAddress myip = Ethernet.localIP(); BLYNK_LOG("My IP: %d.%d.%d.%d",myip[3]); return myip; } Arduino代码: #define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include <CayenneDefines.h> #include <UIPEthernet.h> #include <BlynkSimpleUIPEthernet.h> #include <CayenneEthernetClient.h> #define VIRTUAL_PIN V1 #define VIRTUAL_PIN V0 ... void setup(){ ... int *A=Cayenne.begin(token); ... } void loop(){ ... } 我收到此错误:
题: 如何正确返回数组? 更新: class CayenneEthernetClient : public CayenneClient { public: void begin(const char* token,const byte mac[] = NULL) { BLYNK_LOG("HERE WE ARE 3"); Blynk.begin(token,CAYENNE_DOMAIN,CAYENNE_PORT,GetMACAddress(token,mac)); } private: const byte* GetMACAddress(const char* token,const byte mac[]) { ... return _mac; } byte _mac[6]; }; CayenneEthernetClient Cayenne; 之后,在BlynkProtocol.h调用此开始函数 private: int readHeader(BlynkHeader& hdr); uint16_t getNextMsgId(); protected: void begin(const char* auth) { BLYNK_LOG("HERE WE ARE 2"); this->authkey = auth; } bool processInput(void); 之后,这个begin()在BlynkEthernet.h调用 // DHCP with domain void begin( const char* auth,uint16_t port = BLYNK_DEFAULT_PORT,const byte mac[] = _blynkEthernetMac) { Base::begin(auth); BLYNK_LOG("Getting IP..."); BLYNK_LOG("HERE WE ARE 1"); if (!Ethernet.begin((byte*)mac)) { BLYNK_FATAL("DHCP Failed!"); } // give the Ethernet shield a second to initialize: ::delay(1000); this->conn.begin(domain,port); IPAddress myip = Ethernet.localIP(); BLYNK_LOG("My IP: %d.%d.%d.%d",myip[3]); } 这个begin()最终在BlynkArduinoClient.h被调用 void begin(const char* d,uint16_t p) { BLYNK_LOG("HERE WE ARE 9"); domain = d; port = p; } 串行监视器上的输出:
解决方法
我认为修改代码甚至库的API都不是一个好主意.
我的方法是获取IP地址的方式与Cayenne库相同:调用Ethernet.localIP(): void setup() { Cayenne.begin(token); IPAddress myip = Ethernet.localIP(); } P.S.:错误
可能是因为你只修改了Cayenne类中三个重写的begin()方法之一. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |