我有一个从Web服务接收UID的函数,我需要它将该字符串传递给函数中断,该函数中断在按下按钮后将请求发送回具有匹配UID的服务器。
如何从一个函数到另一个函数获取字符串?
const int buttonPin = D1;
const int ledPin = 13;
void fire(void);
volatile int state = LOW;
//#include <string.h>
char server[] = "xxxxxxxx.com";
TCPClient client;
// name the pins
int red = D3; //RED
int green = D4; //AMBER
int pinCommand;
void setup() {
//Register our Spark function here
Spark.function("led", ledControl);
for (int pin = D3; pin <= D4; ++pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
}
//set RED (D3) LED state to on
digitalWrite(D3, HIGH);
pinMode(buttonPin, INPUT);
attachInterrupt(D1, fire, CHANGE);
Serial.begin(9600);
}
int ledControl(String command) {
//find out the pin number and convert the ascii to integer
int pinCommand = (command.charAt(0) - '0');
String UID = command.substring(2,8);
if ((pinCommand = 1)) {
// GREEN (D5) LED TO ON, RED (D3) LED TO OFF
digitalWrite(D4, HIGH);
digitalWrite(D3, LOW);
}
else {
//GREEN (D5) LED TO OFF, RED (D3) LED TO On
digitalWrite(D4, LOW);
digitalWrite(D3, HIGH);
Serial.println("Fail");
}
return 1;
}
void loop() {
}
void fire() {
if (digitalRead(D4) == HIGH) {
state = !state;
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("POST /deployapp/"+UID+" HTTP/1.1");
Serial.println(UID);
client.print("Host: ");
client.println(server);
client.println("Accept: text/html, text/plain");
client.println();
client.flush();
}
else {
Serial.println("connection failed");
client.stop();
}
}
else {
Serial.println("AUTHENTICATE FIRST");
}
}