Basic Web Client Locks Up When Using Timer
using basic wifiwebclientrepeating sketch basis, i've moved "repeating" part, making web client request, loop , timer interrupt function , board locks every time.
i started basic example sketch , worked fine. i'm using mega2560 wifi101 shield. in example here, have timer firing every 10 seconds i've tried 5 seconds , 20 seconds , still fails. had watchdog timer @ 1 point , rebooted timer interrupt fired. stripped part out make example more simple here.
i want use timer because intention sketch use blynk requires nothing else in loop(). stripped down version of larger sketch logic in timer controlling objects , blynk being used control it. need make web call periodically led me problem.
any ideas on why locking or ideas on how accomplish same thing without using timer or loop?
here's code:
#include <spi.h>
#include <wifi101.h>
#include <timerone.h>
char ssid[] = "ssidhere"; // your network ssid (name)
char pass[] = "passhere"; // network password
int keyindex = 0; // network key index number (needed wep)
int status = wl_idle_status;
// initialize wifi client library
wificlient client;
// server address:
ipaddress server(192,168,200,129);
void setup() {
//initialize serial , wait port open:
serial.begin(115200);
while (!serial) {
; // wait serial port connect. needed native usb port only
}
// check presence of shield:
if (wifi.status() == wl_no_shield) {
serial.println("wifi shield not present");
// don't continue:
while (true);
}
// attempt connect wifi network:
while ( status != wl_connected) {
serial.print("attempting connect ssid: ");
serial.println(ssid);
status = wifi.begin(ssid, pass);
status = wl_connected;
// wait 10 seconds connection:
delay(10000);
}
serial.println("connected");
timer1.initialize(10000000); // once per second
timer1.attachinterrupt(timerinterrupt);
}
void timerinterrupt() {
// if there's incoming data net connection.
// send out serial port. this debugging
// purposes only:
while (client.available()) {
char c = client.read();
serial.write(c);
}
httprequest();
}
void loop() {
}
// method makes http connection server:
void httprequest() {
// close connection before send new request.
// free socket on wifi shield
client.stop();
// if there's successful connection:
if (client.connect(server, 80)) {
serial.println("connecting...");
// send http put request:
client.println("get /latest.txt http/1.1");
client.println("host: 192.168.200.129");
client.println("user-agent: arduinowifi/1.1");
client.println("connection: close");
client.println();
} else {
// if couldn't make connection:
serial.println("connection failed");
}
}
i started basic example sketch , worked fine. i'm using mega2560 wifi101 shield. in example here, have timer firing every 10 seconds i've tried 5 seconds , 20 seconds , still fails. had watchdog timer @ 1 point , rebooted timer interrupt fired. stripped part out make example more simple here.
i want use timer because intention sketch use blynk requires nothing else in loop(). stripped down version of larger sketch logic in timer controlling objects , blynk being used control it. need make web call periodically led me problem.
any ideas on why locking or ideas on how accomplish same thing without using timer or loop?
here's code:
#include <spi.h>
#include <wifi101.h>
#include <timerone.h>
char ssid[] = "ssidhere"; // your network ssid (name)
char pass[] = "passhere"; // network password
int keyindex = 0; // network key index number (needed wep)
int status = wl_idle_status;
// initialize wifi client library
wificlient client;
// server address:
ipaddress server(192,168,200,129);
void setup() {
//initialize serial , wait port open:
serial.begin(115200);
while (!serial) {
; // wait serial port connect. needed native usb port only
}
// check presence of shield:
if (wifi.status() == wl_no_shield) {
serial.println("wifi shield not present");
// don't continue:
while (true);
}
// attempt connect wifi network:
while ( status != wl_connected) {
serial.print("attempting connect ssid: ");
serial.println(ssid);
status = wifi.begin(ssid, pass);
status = wl_connected;
// wait 10 seconds connection:
delay(10000);
}
serial.println("connected");
timer1.initialize(10000000); // once per second
timer1.attachinterrupt(timerinterrupt);
}
void timerinterrupt() {
// if there's incoming data net connection.
// send out serial port. this debugging
// purposes only:
while (client.available()) {
char c = client.read();
serial.write(c);
}
httprequest();
}
void loop() {
}
// method makes http connection server:
void httprequest() {
// close connection before send new request.
// free socket on wifi shield
client.stop();
// if there's successful connection:
if (client.connect(server, 80)) {
serial.println("connecting...");
// send http put request:
client.println("get /latest.txt http/1.1");
client.println("host: 192.168.200.129");
client.println("user-agent: arduinowifi/1.1");
client.println("connection: close");
client.println();
} else {
// if couldn't make connection:
serial.println("connection failed");
}
}
the serial functions require interrupts enabled. shouldn't use serial calls in interrupt. includes httprequest function, since called interrupt function.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Basic Web Client Locks Up When Using Timer
arduino
Comments
Post a Comment