[英]How to read an array from Arduino library?
我正在使用以太網模塊使用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 char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT,
const byte mac[] = _blynkEthernetMac)
{
...
IPAddress myip = Ethernet.localIP();
BLYNK_LOG("My IP: %d.%d.%d.%d", myip[0], myip[1], myip[2], 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(){
...
}
我收到此錯誤:
錯誤:空值不應該被忽略
題:
如何正確返回數組?
更新:搜索后,在Cayenne.begin()
上定義了Cayenne.begin Cayenne.begin()
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);
之后,在BlynkEthernet.h上調用begin()
// DHCP with domain
void begin( const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
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[0], myip[1], myip[2], myip[3]);
}
最后在BlynkArduinoClient.h上調用了begin()
void begin(const char* d, uint16_t p) {
BLYNK_LOG("HERE WE ARE 9");
domain = d;
port = p;
}
在串行監視器上輸出:
[75] HERE WE ARE 3 [76] MAC: FE-9D-D2-DD-A3-A0 [76] HERE WE ARE 2 [77] Getting IP... [80] HERE WE ARE 1 [5385] HERE WE ARE 9 [5386] My IP: 10.42.0.162
我認為修改代碼或庫的API並不是一個好主意。 我在這里的方法是使用Cayenne庫的相同方式獲取IP地址:調用Ethernet.localIP()
:
void setup() {
Cayenne.begin(token);
IPAddress myip = Ethernet.localIP();
}
PS:錯誤
無效值不應該被忽略
發生這種情況的原因可能是,您只修改了Cayenne
類中三個覆蓋的begin()
方法之一。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.