Help on the Page Display Button Using WiFI Module
javelin
Posts: 18
Hi all
Been trying to figure why the Page Display Buttons is not working; more specifically, the html page does not get updated when the push button input changes.
The terminal shows it is sending the data but the web page info does not change even after couple of refresh. It's always on "Value: Waiting..." This means the req.readyState or req.status is not being met...problem is, I don't have enough experience in programming or debugging to figure this out on my own.
Following is a portion of the original html code where it checks the states:
When running my program, the following first few lines are displayed on the terminal- no event yet:
/btns
getFromPageId = 0
Processing from cog0(main core)...
When buttonP4 is pressed or circuit is closed:
event = Left pin value = 1
Processing from cog1, p4...
0,200,3
10
Incoming GET request, sending 10 <---- it's sending out correct value but the web page is not receiving it
Any suggestion or help is appreciated.
Here's my code; slightly changed from the original example.
Been trying to figure why the Page Display Buttons is not working; more specifically, the html page does not get updated when the push button input changes.
The terminal shows it is sending the data but the web page info does not change even after couple of refresh. It's always on "Value: Waiting..." This means the req.readyState or req.status is not being met...problem is, I don't have enough experience in programming or debugging to figure this out on my own.
Following is a portion of the original html code where it checks the states:
function httpGet(path, callback) { var req = new XMLHttpRequest(); req.open("GET", path, true); req.onreadystatechange = function() { if (req.readyState == 4) if(req.status == 200) callback(req.responseText); else callback("Waiting..."); } req.send(null); }
When running my program, the following first few lines are displayed on the terminal- no event yet:
/btns
getFromPageId = 0
Processing from cog0(main core)...
When buttonP4 is pressed or circuit is closed:
event = Left pin value = 1
Processing from cog1, p4...
0,200,3
10
Incoming GET request, sending 10 <---- it's sending out correct value but the web page is not receiving it
Any suggestion or help is appreciated.
Here's my code; slightly changed from the original example.
#include "simpletools.h" #include "wifi.h" void checkLeft(); void checkRight(); int *otherCog; char event; int id, handle; int buttonId; int buttonP3, buttonP4; int main() { wifi_start(31, 30, 115200, WX_ALL_COM); buttonId = wifi_listen(HTTP, "/btns"); print("getFromPageId = %d\n", buttonId); print("Processing from cog0(main core)... \n"); simpleterm_close(); cog_run(checkLeft, 128); } void checkLeft() { while (1) { int left = input(4); if (left == 1) { wifi_poll(&event, &id, &handle); print("event = %c, id = %d, handle = %d\r", event, id, handle); buttonP4 = input(4); buttonP3 = input(3); dac_ctr(14, 0, 250); simpleterm_open(); print("Left pin value = %d\n", left); wifi_print(GET, handle, "%d%d\r", buttonP4, buttonP3); print("Incoming GET request, sending %d%d\r", buttonP4, buttonP3); simpleterm_close(); } dac_ctr(14, 0, 0); pause(100); } }
Comments
I've reconfigured the communication option and got the wifi poll responses back. This setting appears to be more reliable. Will now continue to integrate my code and see if it holds...if this works, it will be a game changer; no more long cables, and I don't have to unbragged to the people I bragged about the prop wifi capability. l ol
It's hard to debug a moving object if it's attached by a cable.
Integrating it with a web page is a hole different story.
Mike
It was the connection options that caused me grief; really need to pay attention and test those out specially when moving from non-wifi to wifi.
This is beautiful to se:
For now, this web page notification is perfect for my purpose. It's a great potential solution to a manual and frustrating task.
Now, to IFTTT I go! why not!
In the browser you type http://<your ip address>/GetValue
Mike
Thanks for your contributions on the WX wifi module, you have become a center-of-expertise for this Prop area!
Do you have any tips, code or projects on using UDP on the WX wifi module?
I did some brief research and reading, and it seems possible, although I did not delve any deeper at that time.
Thanks in advance, and I apologize if I have missed some obvious UDP object or tutorial. . .
Actually the SimpleIDE uses UDP to contact the WX WiFi module and get the address of it. This is running at a different level than the front end code we have access to. I have added some code to the firmware that allows me to turn that UDP connection off and on but have not looked at how I might build in my own UDP traffic.
It would be nice if it supported UDP as then we could build projects that send data out and in without having to know what we are talking to.
Mike