Web 通話の結果に基づいて、リモート ドア オープナーを設定するためのスケッチに取り組んでいます。WiServer を実行している BlackWidow Arduino があり、Wi-Fi は正常に動作し、URL から結果を取得できます。コンテンツとして 0 または 1 を返すだけです。
問題は、relayControlState が常に HIGH である私のループにあり、リレーをオフ/オンにするループを取得できないようです。
シンプルな「ブリンカー」スケッチを使用するだけで、リレーを正常に動作させることができます。リレーが機能しないのは、サーバーのフェッチ コードと絡み合っている場合のみです。私は何が欠けていますか?コードは以下です。RelayControlState が WiServer.getStatus コールバック内で更新されないのはなぜですか? リレーは切り替えるのに十分なジュースを得ていませんか?
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,10}; // IP address of WiShield 192.168.1.10
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[] = {"monitored"}; // max 32 bytes
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // max 64 characters
// setup the wireless mode
// infrastructure - connect to AP
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// IP Address for macpro.local
uint8 ip[] = {192,168,1,12};
// End of wireless configuration parameters ----------------------------------------
// A request that gets the aggregate status of the build system
GETrequest getStatus(ip, 80, "macpro.local", "/open-says-me/index.html");
const int relayPin = 12;
int relayControlState = HIGH;
// Function that sets pin/light states
// BEWARE: THIS FUNCTION IS CALLED MULTIPLE (2) TIMES PER HTTP REQ
// Hidden call before/after call that returns payload 0, 1, 2, or null
void setRelayControlState(char* data, int len) {
// Serial.print("=========================\n\nLEN:\n");
// Serial.print(len);
if(len > 0) {
Serial.print("\nDATA:");
Serial.print(data[len - 1]);
Serial.print("\n");
// Serial.print("\n\nsetRelayControlState\n\n");
if(data[len - 1] == '0') {
relayControlState = LOW;
Serial.print("SET LOW");
}
if(data[len-1] == '1') {
relayControlState = HIGH;
Serial.print("SET HIGH");
}
} else {
relayControlState = LOW;
}
}
void setup() {
pinMode(relayPin, OUTPUT);
Serial.begin(57600);
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
WiServer.init(NULL);
// Enable Serial output and ask WiServer to generate log messages (optional)
WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server
getStatus.setReturnFunc(setRelayControlState);
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;
void loop(){
// Check if it's time to get an update
if (millis() >= updateTime) {
// Get another update 15s from now
updateTime += 1000 * 5;
getStatus.submit();
}
// Run WiServer
WiServer.server_task();
// turn on light pins based on stored vals
Serial.print("\nrelayControlState: ");
Serial.print(relayControlState);
Serial.print("\n");
digitalWrite(relayPin, relayControlState);
delay(10);
}