Shop OBEX P1 Docs P2 Docs Learn Events
Help on the Page Display Button Using WiFI Module — Parallax Forums

Help on the Page Display Button Using WiFI Module

javelinjavelin Posts: 18
edited 2019-03-17 00:44 in Propeller 1
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:
      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

  • This WIFI module is a POS. It would be nice if it's consistently failing so that I know its a bad device. One time it's giving me a nice listing of the event, handle, and id. Next thing you know, without touching the device but just rerunning the SAME program, it spits out full of chinese garbage characters. Trying to become productive but with this device, it's not giving me anything but frustrations. Will edit this post to something more positive when its working or if the wifi module is finally made into millions of pieces and it's in the trash can.
  • You never mentioned which WiFi module it is.
  • WX ESP866 DIP. I've read on another post where the wifi module was to be used to control his romba. He had a similar issue with the wifi_poll and I don't think he ever got it to worked.

    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
  • I like the WiFi module because it allows me to update code and display debug information without a cable attached.

    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
  • javelinjavelin Posts: 18
    edited 2019-03-17 16:08
    Howly Smile, it works! OK, I'll take back the mean words I posted above. The WiFI module works as designed.

    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:
    Incoming GET request, sending 10
    event = G, id = 1, handle = 5
    Left pin value = 1
    Processing from cog1, p4... 
    

    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 case you want the KISS method here is a program with no webpage at all.
    #include "wifi.h"
    #include "simpletools.h"
    
    
    int i;
    int WebPage;
    char Request;
    int id, handle;
    
    int main()
    {
      
      wifi_start(31, 30, 115200, WX_ALL_COM);
    
      WebPage = wifi_listen(HTTP, "/GetValue");
      
      print("Hello World!\n");
      
      i = 0;
      
      while(1)
      {
        wifi_poll(&Request, &id, &handle);
        if (Request == 'G')
        {
          printi("Get a request\n");
          if (WebPage == id)
          {
            printi("Handling request\n");
            wifi_print(GET, handle, "<html>\r<head><title>test page</title></head>\r<body>\r<h1>Value: %d</h1>\r</body>\r</html>\r", i++);
          }
        }
        pause(1000);              
      }  
    }
    

    In the browser you type http://<your ip address>/GetValue

    Mike
  • iseries,
    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. . .
  • I had looked at doing UDP a while back as I use UDP on a home weather station I built. I am currently using the XBee module as it was all that was available at the time I built it. Since then I have moved on to the ESP01 and ESP8266 module as they are cheaper and are easy to program with Arduino.

    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
Sign In or Register to comment.