Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE WiFi - Page 4 — Parallax Forums

SimpleIDE WiFi

12467

Comments

  • edited 2017-02-13 21:23
    It's working on my system (C code 3rd post above, html 10th post above). I let it run while I was at lunch, and now clicking Update just gave me 12670.

    At the start, using Run with Terminal, I see this in the SimpleIDE Terminal:

    WiFi prototype for Roomba
    debug-1
    PageId = 1
    debug-2
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    ...

    I see this repeatedly in SimpleIDE Terminal when I do not click the Update button:

    ...
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    ...

    This is the sequence I see in SimpleIDE Terminal when I click the Update button:

    ...
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    Event = G, id = 1, handle = 5
    Incoming GET request, sending 13531
    debug-3
    debug-4
    Event = S, id = 0, handle = 5
    Event = N, id = 0, handle = 0
    Event = N, id = 0, handle = 0
    ...

    Ideas of things to check:

    Battery power - if your batteries are tired, you might see it first in the Wi-Fi module's performance, it could cause a voltage dip when it pulls extra current to transmit.

    Are your Wi-Fi module and computer no the same network and is your Wi-Fi module in STA mode?
    (That's the recipe for best results.)

    Did you load the page into your Wi-Fi module using the Files page?
    (http://Your-Wi-Fi-Module's-IP-Address/update-ffs.html).

    Did you access your page through the Wi-Fi module at http://Your-Wi-Fi-Module's-IP-Address/files/your-web-page's-name.html? (I sometimes open a copy that's on my computer by accident and end up scratching my head for a while.)

    You might want to paste from the SimpleIDE Terminal into a post if it doesn't match what I pasted above.
  • That one just does not want to work for me. The last time I tried, I just copied as is from the examples folder the .side+.c and the html file, without doing any changes, and ran it. I was being very careful to make sure all steps were accomplished. So at this point I am not sure what is going on.

    I have been trying some of the other examples, and they seem to be working as expected. I think I will try adapting the ActvityBot control example to see if I can get the Roomba to move.

    Ray
  • Andy, I just reread your previous post, you are saying that you see the values change in the terminal window, but are you seeing the same number appear in the html screen? My problem now is that I do not see the values change in the html screen, I just get the same number appear every time I click update.

    Ray
  • Rsadeika wrote: »
    I could not get the val-from-micro html to work. I was expecting the value to change every time you clicked on update, but that did not happen. Now, I did try the p26/p27 LED example, that worked as expected.

    Ray
    I don't understand your JavaScript code. You invoke a function called "callback" but that function is not defined. Did you mean to call "useMcuReply"?

  • Below is the html code that I am using, that is in the downloaded zip file. I just removed the delete
    section, I figured it is not necessary.

    Ray
    <!DOCTYPE html>
    <html>
      <!-- Start of section to delete -->
        <b>Setup:</b><br>
        &nbsp &nbsp &#9989 &nbsp Upload this page to your Wi-Fi module.<br>
        &nbsp &nbsp &#9989 &nbsp Open this page from http://your-wi-fi-module's-ip/files/val-from-micro.html.<br>
        &nbsp &nbsp &#9989 &nbsp Open "Val from Micro Host.side" with SimpleIDE,<br> 
        and load the .c program into your Propeller board. <br>
        &nbsp &nbsp &#x1F56E &nbsp More info at http://learn.parallax.com/propeller-c-wx-wi-fi
        <br><br>
      <!-- End of section to delete -->
      <body>
      
        <H2>Value from Microcontroller</H2> 
    
        <p>Click Update to see number from Micro:</p> 
        <button onclick="getFromMcu()">Update</button>
        <p id="value">Waiting...</p>
    
        <script>
    
          function useMcuReply(response)
          {
            var val = document.getElementById("value");
            val.innerHTML = "Value: " + response;
          }
    
          function getFromMcu()
          {
            httpGet("/tpfm", useMcuReply);
          }
    
          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);
          }
    
        </script>
      </body>
    </html>
    
  • My question still stands. It looks like the function useMcuReply updates the web page with the new value but the code calls a function called "callback" when it gets a new value. I don't see how that could update the web page. Try changing "callback" to "useMcuReply".
  • edited 2017-02-14 04:16
    Hi David, I already tested Ray's C and JavaScript together, and reported that they worked. Since they worked for me, and not for him, it would be good to find out what Ray is doing differently, or maybe what's different about his setup. I asked him an initial series of questions, but did not get specifics in reply. So, I think it might work better for him if he calls our Tech Support and gets some realtime help.

    The callback parameter in httpGet receives useMcuReply as a parameter from the httpGet(path, useMcuReply) call in the getFromMcu function. So, inside httpGet, callback(req.responseTest) is equivalent to useMcuReply(req.responseText).

    This arrangement makes it so that nobody has to do any editing inside httpGet. Responses to other events can also be added in other functions, and different functions can also be called back, all without editing httpGet.

    http://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c/page-requests-info-propeller

    http://stackoverflow.com/questions/13286233/pass-a-javascript-function-as-parameter
  • edited 2017-02-14 02:33
    Hi Ray, at this point, I would recommend calling our Tech Support because this game of 20 Questions could get way too drawn out. Their toll-free number is here:

    https://www.parallax.com/company/company

    P.S. What browser are you using? If it's not chrome, it would be interesting to find out if it does work in Chrome, but not in your particular browser.
  • Hi David, I already tested Ray's C and JavaScript together, and reported that they worked. Since they worked for me, and not for him, it would be good to find out what is Ray doing differently, or maybe what's different about his setup. I asked him a series of questions, but did not get specifics in reply. So, I think it might work better for him if he calls our Tech Support and get some realtime help.

    The callback parameter in httpGet receives useMcuReply as parameter from httpGet(path, useMcuReply) in the getFromMcu function. So, inside httpGet, callback(req.responseTest) is equivalent to useMcuReply(req.responseText). This arrangement makes it so that nobody has to do any editing inside httpGet. Responses to other html events can also be added, and different functions can b called back, also without editing httpGet.

    http://stackoverflow.com/questions/13286233/pass-a-javascript-function-as-parameter

    http://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c/page-requests-info-propeller

    Oops, sorry! I missed the "callback" parameter. Forget what I said. It seems that the most likely cause of this is that the request is never getting to the Propeller for some reason. The DBG output would help diagnose this. Could we give Ray the new firmware that I posted today as sort of a "field test" of it?

  • The firmware that has a page for displaying debug info that makes the Propeller Plug unnecessary? (That's really awesome BTW!)

    Since Parallax has't tested it yet, there's always some risk that it will add one or more bugs on top of what we are trying to diagnose. Of course, it could also give a faster indicator of what's going on. I'd say test it with Ray's last C file (3rd from bottom on page 3) and HTML (10th from bottom on page 3). If it works, insert a bug, and check to make sure it reports correctly. If yes and yes, then, take it up with Ray over PM so that we don't send a minimally tested .ota file into circulation.

    Since I haven't posted the Chrome developer tools tutorial yet:

    Another approach would be to open up Chrome, right click the application page and select Inspect to open the Developer Tools. After clicking the vertical ... in the upper-right corner and selecting Undock into separate window, click the Network heading. Then, click the page's Update button and see if a tpfm entry appears in the list. Click it again and check if another tpfm appears. You can click each name, and see what the value is.

    Also, in the Developer Tools' Sources tab, double click the HTML file in the left column to view its code in the center column, and click the numbers to the left of the statements to set breakpoints. They can be used to check if the code makes it to various points in the JavaScript. When the code gets to a breakpoint, there'll be a right pointing triangular play button near the top of the right column for resuming execution to the next breakpoint.
  • Ray, one more thing. In your C code, change the pause 100 to pause 500. If your terminal is getting behind on displaying things, it might seem like it's not responding simply because it's catching up on 50 lines with Event = N... I think that that problem was fixed in the 1.0.2 to 1.1. updates, but just in case, give it a try.
  • edited 2017-02-14 04:34
    Interesting... Ray's find just came up another thread too:

    http://forums.parallax.com/discussion/166076/wifi-module-32420-setup-question#latest

    I'm beginning to wonder if it's a certain browser or OS. Maybe I missed something and a particular feature is not supported by MS or Firefox or something. I just rechecked Chrome and Safari, both OK.

    P.S. Any additional info you can provide about your OS, browser, setup, security settings and security software would be appreciated.
  • I just installed Chrome, and ran the val-from-micro html program, and it WORKS as expected.

    My desktop system is a Windows 7 64-bit with IE, the latest version, installed. So, the val-from-micro html works with Chrome, but it does not work with IE. I would hate to get locked into just using Chrome, but I do not want to start wondering about which WX Wifi html examples will work with which browser. Does Parallax have the resources to create their own browser? That might solve some usage problems.

    So I guess my Parallax WX WiFi DIP module is not broken, and it should work as expected, when using the Chrome browser. Since Andy is using a Chrome browser on his Samsung device, could the problem also extend to the OS, which would make this a very annoying situation.

    Ray
  • I went ahead and downloaded Firefox browser on my Windows 7 desktop, and tested the val-from-micro html program, and it WORKS as expected. But, this does not verify that there would not be an OS issue also. For all I know, when I run the p26/p27 LED example, I might start to see issues.

    I will leave it up to somebody else to test the other available browsers that might be in use.

    Ray
  • Rsadeika wrote: »
    I just installed Chrome, and ran the val-from-micro html program, and it WORKS as expected.

    My desktop system is a Windows 7 64-bit with IE, the latest version, installed. So, the val-from-micro html works with Chrome, but it does not work with IE. I would hate to get locked into just using Chrome, but I do not want to start wondering about which WX Wifi html examples will work with which browser. Does Parallax have the resources to create their own browser? That might solve some usage problems.

    So I guess my Parallax WX WiFi DIP module is not broken, and it should work as expected, when using the Chrome browser. Since Andy is using a Chrome browser on his Samsung device, could the problem also extend to the OS, which would make this a very annoying situation.

    Ray
    If it doesn't work with IE then it would be interesting to see what the IE debug console shows. Do you know how to enable it?

  • I just opened up Tools->Internet options->Advanced, and in the browser section, I see Disable script...(Internet Explorer). I guess you are supposed to uncheck that, and then restart the computer. If I decide to try this, what am I expected to see when I run the val-from-micro html program? Not sure if I would be capturing any info that would be of use.

    Ray
  • "Disable script" will certainly cause a problem since it probably won't execute your JavaScript code at all. Another possible problem might be that IE used to do HTTP requests differently than other platforms although that may be fixed in newer versions of IE. What I was mostly wanting to know from the debug console in IE is whether it displayed any error messages.
  • What I was mostly wanting to know from the debug console in IE is whether it displayed any error messages.

    Nope.

    Ray
  • Does it work now that you've allowed scripts?
  • Still does not work.

    I think I will just have to start using Firefox for the WX WiFi stuff. I like Firefox better than Chrome. At least now if I run into a problem I will know to check if the browser is the culprit.

    Ray
  • Something strange is going on now with Firefox, it seems to run OK when you run the standard val-from-micro html. But, when I change:
    wifi_print(GET, handle, "%f", vy);
    so it would print out a float number, in the html, Firefox falls apart, but Chrome seems to be able to handle that. So, I guess I am locked into using Chrome. I thought this html/js stuff was supposed be portable, able to run on any system, in the same way.

    Ray
  • I thought I would try doing an application to control my Roomba. This program seems to work with Firefox and Chrome.

    The one thing that I did notice, when working with the html, even though, in the firmware window, when you hit the clear the files, it does not seem to be clearing. You have to turn off the WiFi module in order for it to take affect, at least that is what my module is doing.

    I did run the robot around a bit, and I noticed there is a definite hesitation between when you hit the button in the html, and the robot acting on it. I wonder if the further the robot goes away from the hotspot signal, the longer the reaction time. This will be rocket physics as I get the robot more things to do.

    Ray
    /*
      mycrgo.c
    
      Feb 15, 2017
      Test program.
    */
    #include "simpletools.h"
    #include "wifi.h"
    #include "simpletext.h"
    #include "fdserial.h"
    serial *roomba;
    
    /* Create control commands. */
    static volatile int speed_right = 50;
    static volatile int speed_left = 50;
    static volatile int turn_left = 35;
    static volatile int turn_right = 35;
    static volatile int highbyte,lowbyte;
    static volatile float newbyte;
    
    void CRstop();
    void CRfore();
    void CRback();
    void CRleft();
    void CRrite();
    void CRsafe();
    void CRstart();
    void CRfull();
    
    
    
    int event, id, handle;
    int navId;
    char buttonCmd; 
    
    int main()
    {
      // Add startup code here.
      /* Start up comms with the WiFi.*/
      roomba = fdserial_open(10, 9, 0, 115200);
      pause(250);
      wifi_start(31,30,115200,WX_ALL_COM);
      navId = wifi_listen(HTTP, "/bot");
    
      //CRstart();
      //pause(400);
      CRfull();
         
      while(1)
      {
        // Add main loop code here.
        wifi_poll(&event, &id, &handle);
        if(event == 'P')
        {
          if(id == navId)
          {
            pause(500);
            wifi_scan(POST, handle, "go%c", &buttonCmd);
          }        
        }
        if(buttonCmd != 0)
        {
          switch(buttonCmd)
          {
            case 'S':
              CRstop();
              break;
            case 'F':
              CRfore();
              break;
            case 'B':
              CRback();
              break;
            case 'L':
              CRleft();
              break;
            case 'R':
              CRrite();
              break;
          }        
        }      
      }  
    }
    
    
    /* Create commands */
    void CRstop()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
    }
    
    void CRfore()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_right)&0xFF));
      fdserial_txChar(roomba,((speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_left)&0xFF));
    }
    
    void CRback()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,((-speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_right)&0xFF));
      fdserial_txChar(roomba,((-speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_left)&0xFF));    
    }
    
    void CRleft()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_right)&0xFF));
      fdserial_txChar(roomba,((-turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_left)&0xFF));
    }
    
    void CRrite()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((-turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_right)&0xFF));
      fdserial_txChar(roomba,((turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_left)&0xFF));
    }
    
    void CRsafe()
    {
      fdserial_txChar(roomba,128);
      pause(400);
      fdserial_txChar(roomba,131);  
    }
    
    void CRstart()
    {
      fdserial_txChar(roomba,128);
    }        
    
    void CRfull()
    {
      fdserial_txChar(roomba,128);
      pause(400);
      fdserial_txChar(roomba,132);
    }  
    
    <!DOCTYPE HTML>
    <html>
    <body>
    	<div align="center">
    	<font face="Arial" size=6 color="red">
    		I am a Roomba!
    	</font>
    	<br>
    	<font face="Arial" size=4 color="blue">
    	    Manual Control
    	</font>
    	<br>
    	<button onclick="navBtns('F');">Forward </button>
    	<br>
    	<button onclick="navBtns('L');">Left</button>
    	<button onclick="navBtns('S');";>Stop</button>
    	<button onclick="navBtns('R');">Right</button>
    	<br>
    	<button onclick="navBtns('B');">Backward</button>
    	</div>
    </body>	
    	<script>
    	function navBtns(direction)
    	{
    		httpPost("/bot", "go=" + direction);
    	}
    	function httpPost(path, param)
    	{
    		var req = new XMLHttpRequest();
    		req.open("POST", path, true);
    		req.setRequestHeader("Content-type",
    		"application/x-www-form-urlencoded");
    		req.send(param);
    	}
    	</script>
    </html>
    
  • I need some help or direction as to how too use radio buttons.

    The mode settings is what I am after, I put in some regular buttons, that work as expected, but I am having some trouble getting the radio buttons to work correctly. There can only be one mode setting for the Roomba, so I thought the radio buttons would be the tool to use.

    Any help would be appreciated.

    Ray
    <!DOCTYPE HTML>
    <html>
    <body>
    	<div align="center">
    	<font face="Arial" size=6 color="red">
    		I am a Roomba!
    	</font>
    	<br>
    	<font face="Arial" size=4 color="blue">
    	    Manual Control
    	</font>
    	<br>
    	<button onclick="navBtns('F');">Forward </button>
    	<br>
    	<button onclick="navBtns('L');">Left</button>
    	<button onclick="navBtns('S');";>Stop</button>
    	<button onclick="navBtns('R');">Right</button>
    	<br>
    	<button onclick="navBtns('B');">Backward</button>
    	<br>
    	<font face="Arial" size=2 color="brown">
    	    Roomba Mode Settings
    	</font>
    	<br>
    	<button onclick="navBtns('0');">Start</button>
    	<button onclick="navBtns('1');">Safe</button>
    	<button onclick="navBtns('2');">Full</button>
    	<br>
    	<input type="radio" onclick="navBtns('X');"> Start
    	<input type="radio" onclick="navBtns('Y');"> Safe
    	<input type="radio" onclick="navBtns('Z');"> Full
    	</div>
    </body>	
    	<script>
    	function 
    	function navBtns(direction)
    	{
    		httpPost("/bot", "go=" + direction);
    	}
    	function httpPost(path, param)
    	{
    		var req = new XMLHttpRequest();
    		req.open("POST", path, true);
    		req.setRequestHeader("Content-type",
    		"application/x-www-form-urlencoded");
    		req.send(param);
    	}
    	</script>
    </html>
    
    /*
      mycrgo.c
    
      Feb 15, 2017
      Test program.
    */
    #include "simpletools.h"
    #include "wifi.h"
    #include "simpletext.h"
    #include "fdserial.h"
    serial *roomba;
    
    /* Create control commands. */
    static volatile int speed_right = 50;
    static volatile int speed_left = 50;
    static volatile int turn_left = 35;
    static volatile int turn_right = 35;
    static volatile int highbyte,lowbyte;
    static volatile float newbyte;
    
    void CRstop();
    void CRfore();
    void CRback();
    void CRleft();
    void CRrite();
    void CRsafe();
    void CRstart();
    void CRfull();
    
    
    
    int event, id, handle;
    int navId;
    char buttonCmd;
    char modeCmd; 
    
    int main()
    {
      // Add startup code here.
      /* Start up comms with the WiFi.*/
      roomba = fdserial_open(10, 9, 0, 115200);
      pause(250);
      wifi_start(31,30,115200,WX_ALL_COM);
      navId = wifi_listen(HTTP, "/bot");
    
      //CRstart();
      //pause(400);
      //CRsafe();
         
      while(1)
      {
        // Add main loop code here.
        wifi_poll(&event, &id, &handle);
        if(event == 'P')
        {
          if(id == navId)
          {
            pause(500);
            wifi_scan(POST, handle, "go%c", &buttonCmd);
          }        
        }
    
        if(buttonCmd != 0)
        {
          switch(buttonCmd)
          {
            case 'S':     // Stop
              CRstop();
              break;
            case 'F':     // Foreward continuous
              CRfore();
              break;
            case 'B':     // Backward continuous
              CRback();
              break;
            case 'L':     // Left continuous
              CRleft();
              break;
            case 'R':     // Right continuous
              CRrite();
              break;
            case 'X':
              CRstart();
              break;
            case 'Y':
              CRsafe();
              break;
            case 'Z':
              CRfull();
              break;
          }
          buttonCmd = 0;        
        }
        pause(200);      
      }  
    }
    
    
    /* Create commands */
    void CRstop()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
    }
    
    void CRfore()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_right)&0xFF));
      fdserial_txChar(roomba,((speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_left)&0xFF));
    }
    
    void CRback()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,((-speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_right)&0xFF));
      fdserial_txChar(roomba,((-speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_left)&0xFF));    
    }
    
    void CRleft()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_right)&0xFF));
      fdserial_txChar(roomba,((-turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_left)&0xFF));
    }
    
    void CRrite()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((-turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_right)&0xFF));
      fdserial_txChar(roomba,((turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_left)&0xFF));
    }
    
    void CRsafe()
    {
      //fdserial_txChar(roomba,128);
      //pause(400);
      fdserial_txChar(roomba,131);  
    }
    
    void CRstart()
    {
      fdserial_txChar(roomba,128);
    }        
    
    void CRfull()
    {
      //fdserial_txChar(roomba,128);
      //pause(400);
      fdserial_txChar(roomba,132);
    }  
    
  • edited 2017-02-16 22:22
    Rsadeika wrote: »
    ..., and I noticed there is a definite hesitation between when you hit the button in the html, and the robot acting on it...
    [/code]

    Hi Ray,

    A more responsive alternative to HTTP POST/GET that the Wi-Fi module supports is WebSockets. The example that starts with ws_ in the ..../Examples/Propeller C/ would be one to try. After uploading the page and running the C program, refresh the page to make the connection.

    Andy

    P.S. Another speed test you could try with the HTTP application's C code would be to comment out the pause commands.
  • Hi again Ray,

    If the radio buttons all share the same name, they will then be mutually exclusive. Here is an example where I used name="setting":
    	<input type="radio" name="setting" onclick="navBtns('X');"> Start
    	<input type="radio" name="setting" onclick="navBtns('Y');"> Safe
    	<input type="radio" name="setting" onclick="navBtns('Z');"> Full
    

    The last html you posted has a stray function statement. If you want to see the errors this causes in the page in Chrome, (recommended, because they are akin to checking for compiler errors in C), right-click the web page and select Inspect. Then, click the Sources tab, double-click the html file in the left column, and then examine the code in the center column for red error messages.
  • edited 2017-02-16 23:40
    It started out with a red 'x' that you can click by function navBtns..., which is right below the stray function statement. When I clicked each radio button, it also showed 'x' marks by the html elements because they were calling a function that that stray function statement caused not to exist.

    Capture.PNG
    1075 x 876 - 180K
  • Rsadeika wrote: »
    The one thing that I did notice, when working with the html, even though, in the firmware window, when you hit the clear the files, it does not seem to be clearing. You have to turn off the WiFi module in order for it to take affect, at least that is what my module is doing.

    If you leave a file open, the browser will hold onto it. Try this, click Empty with something hosted by the Wi-Fi module open in a browser. After clicking Empty, click the browser's refresh button on your test page. It should then give you "404 File not found." That's because the page you requested is no longer in the Wi-Fi module's file system.
  • I got this application working. After you load and start the html, I now always do a reload or refresh, to make sure that you have the html that you want loaded.

    The radio buttons now work the way they are supposed to, and I added the update thing-ma-jig in the bottom left. For now I just have a 'val++' value, which is also working as expected. That will be changed over to reflect the raw battery voltage value which will probably be run in its own COG using the ADC mechanism.

    So this incorporates two of the lessons from the Learn site, the third lesson, using the checkbox to control the LEDs, not sure with what I can incorporate that that would be appropriate to the robot.

    Ray

    /*
      mycrgo.c
    
      Feb 15, 2017
      Test program.
    */
    #include "simpletools.h"
    #include "wifi.h"
    #include "simpletext.h"
    #include "fdserial.h"
    serial *roomba;
    
    /* Create control commands. */
    static volatile int speed_right = 50;
    static volatile int speed_left = 50;
    static volatile int turn_left = 35;
    static volatile int turn_right = 35;
    static volatile int highbyte,lowbyte;
    static volatile float newbyte;
    
    void CRstop();
    void CRfore();
    void CRback();
    void CRleft();
    void CRrite();
    void CRsafe();
    void CRstart();
    void CRfull();
    
    
    
    int event, id, handle;
    int navId;
    char buttonCmd;
    char modeCmd;
    int val; 
    
    int main()
    {
      // Add startup code here.
      /* Start up comms with the WiFi.*/
      roomba = fdserial_open(10, 9, 0, 115200);
      pause(100);
      wifi_start(31,30,115200,WX_ALL_COM);
      navId = wifi_listen(HTTP, "/bot");
         
      while(1)
      {
        // Add main loop code here.
        val++;
        wifi_poll(&event, &id, &handle);
        if(event == 'G')
        {
          if(id == navId)
          {
            wifi_print(GET, handle, "%d", val);
          }        
        }
        else if(event == 'P')
        {
          if(id == navId)
          {
            wifi_scan(POST, handle, "go%c", &buttonCmd);
          }        
        }
        if(buttonCmd != 0)
        {
          switch(buttonCmd)
          {
            case 'S':     // Stop
              CRstop();
              break;
            case 'F':     // Foreward continuous
              CRfore();
              break;
            case 'B':     // Backward continuous
              CRback();
              break;
            case 'L':     // Left continuous
              CRleft();
              break;
            case 'R':     // Right continuous
              CRrite();
              break;
            case 'X':     // Mode Start
              CRstart();
              break;
            case 'Y':     // Mode Safe
              CRsafe();
              break;
            case 'Z':     // Mode Full
              CRfull();
              break;
          }
          buttonCmd = 0;        
        }
        pause(200);
      }  
    }
    
    
    /* Create commands */
    void CRstop()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
      fdserial_txChar(roomba,0);
    }
    
    void CRfore()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_right)&0xFF));
      fdserial_txChar(roomba,((speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((speed_left)&0xFF));
    }
    
    void CRback()
    {
      fdserial_txChar(roomba,145);
      fdserial_txChar(roomba,((-speed_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_right)&0xFF));
      fdserial_txChar(roomba,((-speed_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-speed_left)&0xFF));    
    }
    
    void CRleft()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_right)&0xFF));
      fdserial_txChar(roomba,((-turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_left)&0xFF));
    }
    
    void CRrite()
    {
      fdserial_txChar(roomba,145);  
      fdserial_txChar(roomba,((-turn_right)>>8)&0xFF);
      fdserial_txChar(roomba,((-turn_right)&0xFF));
      fdserial_txChar(roomba,((turn_left)>>8)&0xFF);
      fdserial_txChar(roomba,((turn_left)&0xFF));
    }
    
    void CRsafe()
    {
      //fdserial_txChar(roomba,128);
      //pause(400);
      fdserial_txChar(roomba,131);  
    }
    
    void CRstart()
    {
      fdserial_txChar(roomba,128);
    }        
    
    void CRfull()
    {
      //fdserial_txChar(roomba,128);
      //pause(400);
      fdserial_txChar(roomba,132);
    }  
    
    
    <!DOCTYPE HTML>
    <html>
    <body>
    	<div align="center">
    	<font face="Arial" size=6 color="red">
    		I am a Roomba!
    	</font>
    	<br>
    	<font face="Arial" size=6 color="cyan">
    	     where is that ActivityBot
    	</font>
    	<br>
    	<font face="Arial" size=4 color="blue">
    	    Manual Control
    	</font>
    	<br>
    	<button onclick="navBtns('F');">Forward </button>
    	<br>
    	<button onclick="navBtns('L');">Left</button>
    	<button onclick="navBtns('S');";>Stop</button>
    	<button onclick="navBtns('R');">Right</button>
    	<br>
    	<button onclick="navBtns('B');">Backward</button>
    	<br>
    	<font face="Arial" size=2 color="brown">
    	    Roomba Mode Settings
    	</font>
    	<br>	
    	<input type="radio" name="setting" onclick="navBtns('X');"> Start
    	<input type="radio" name="setting" onclick="navBtns('Y');"> Safe
    	<input type="radio" name="setting" onclick="navBtns('Z');"> Full
    	
    	</div>
    	<br>
    	<font face="Arial" size=2 color="blue">
    	    Raw Battery Voltage
    	</font>
    	<br>	
    	<button onclick="getFromMcu()">Update</button>
    	<p id="value">Voltage</p>
    </body>	
    	<script>
    	function useMcuReply(response)
    	{
    		var val = document.getElementById("value");
    		val.innerHTML = "Value: " + response;
    	}
    	function getFromMcu()
    	{
    		httpGet("/bot", useMcuReply);
    	}
    	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);
          }
    
    	function navBtns(direction)
    	{
    		httpPost("/bot", "go=" + direction);
    	}
    	function httpPost(path, param)
    	{
    		var req = new XMLHttpRequest();
    		req.open("POST", path, true);
    		req.setRequestHeader("Content-type",
    		"application/x-www-form-urlencoded");
    		req.send(param);
    	}
    	</script>
    </html>
    
  • After doing some of the lessons at the Learn site, I thought I would try taking some of them, and put them into one html/.side application. Not sure if this will be of any value to anybody else, but it gave me a chance to use some of the aged brain cells.

    Ray
    /*
      wifi_base.c
      
      Feb 17, 2017
      A wifi base starting program.
      
    */
    #include "simpletools.h"
    #include "wifi.h"
    
    int event, id, handle;
    int anyId;
    int any;
    char anyCmd;
    int pin,state;
    
    
    int main()
    {
      // Add startup code here.
      wifi_start(31,30,115200,WX_ALL_COM);
      anyId = wifi_listen(HTTP, "/any");
      
    /* Set pin direction */
      set_direction(27,1);
     
      while(1)
      {
        // Add main loop code here.
        wifi_poll(&event, &id, &handle);
        if(event == 'P')
        {
          if(id == anyId)
          {
            wifi_scan(POST, handle, "io%d%d", &pin, &state);
            set_output(pin, state);
            wifi_scan(POST, handle, "go%c", &anyCmd);
          }        
        }
    /* The GET event */
        else if(event == 'G')
        {
          if(id == anyId)
          {
            wifi_print(GET, handle, "%d", any);
          }        
        }
        if(anyCmd != 0)
        {
          // Control things
          switch(anyCmd)
          {
            case 'X':
              high(26);
              break;
            case 'Y':
              low(26);
              break;
          }        
        }
    /* Used by the GET */
        any++;                  
      }  
    }
    
    <!-- wifi_base.html -->
    <!DOCTYPE HTML>
    <html>
    	<body>
    	<script>
    	var dt = new Date();
    	document.write("Date and Time: " + dt);
    	</script>
    	<br>
    		<div align="center">
    			
    			<br>
    			<font face="Arial" size=6 color="red">
    				Lessons Learned
    			</font>
    			<br>
    			<font face="Arial" size=2 color="brown">
    				Button Control
    			</font>
    			<br>
    			<font face="Arial" size=2 color="brown">
    				Activity Board WX P26 LED
    			</font>
    			<br>
    			<button onclick="anyBtns('X');">On</button>
    			<button onclick="anyBtns('Y');">Off</button>
    			<br>
    			<br>
    			<font face="Arial" size=2 color="brown">
    				Use of checkbox P27 LED
    			</font>
    			<br>
    			P27: <input type="checkbox" id="27" 
    			onclick="ledVals(id)">
    
    			<p id="ledval"></p>
    			<br>
    			<font face="Arial" size=2 color="grey">
    				Use of radio buttons
    			</font>
    			<br>
    			<input type="radio" name="choices" onclick="choice1();"> Spin
    			<input type="radio" name="choices" onclick="choice2();"> PropGCC
    			<input type="radio" name="choices" onclick="choice3();"> PASM
    			<p id="myMsg"></p>			
    		</div>
    		<br>
    		<button onclick="getFromMcu()">Update</button>
    		<p id="value">Values</p>
    					
    	</body>
    	<script>
    	function useMcuReply(response)
    	{
    		var val = document.getElementById("value");
    		val.innerHTML = "Value: " + response;
    	}
    	function getFromMcu()
    	{
    		httpGet("/any", useMcuReply);
    	}
    	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);
          }
    
    	function anyBtns(direction)
    	{
    		httpPost("/any", "go=" + direction);
    	}
    	function httpPost(path, param)
    	{
    		var req = new XMLHttpRequest();
    		req.open("POST", path, true);
    		req.setRequestHeader("Content-type",
    		"application/x-www-form-urlencoded");
    		req.send(param);
    	}
    	function ledVals(pinId) 
    	{
    		var state = document.getElementById(pinId).checked;
    		console.log(state);
    		var nameVal = "io=pin" + pinId + "state" + Number(state);
    		document.getElementById("ledval").innerHTML = nameVal;
    		httpPost("/any", nameVal);
    	}
    	function choice1()
    	{
    		document.getElementById('myMsg').innerHTML = 'Not sure about this.';
    	}
    	function choice2()
    	{
    		document.getElementById('myMsg').innerHTML = 'Doing it now.';
    	}
    	function choice3()
    	{
    		document.getElementById('myMsg').innerHTML = 'Not sure, thinking...';
    	}
    
    	</script>
    
    </html>
    
  • Yesterday I switched over to adding my Parallax WX WiFi SIP module to the on board original Activity Board. After setting up the program for WiFi, it was working as expected.

    With this setup you cannot program the AB OTA, but it was working just fine using some instructions in the html program. I also did some WiFi signal strength tests to see what kind of coverage you can get. It is only ~15 feet, but the interesting part is on my desktop, it sows the actual signal strength to be high, but it does not communicate with the WX WiFi module. More testing to be done.

    Ray
Sign In or Register to comment.