Forum Update - Announcement about May 10th, 2018 update and your password.

FLiP + WX WiFi base

This is a start for a prototyping base unit; the breadboard has a FLiP module and a WX SIP module. I power it with two li-ion batteries hooked up in a series configuration, to get ~8VDC.

So far it is working as expected, but a weird thing is occurring. I have an LED connected to P0, and when the px1_flip.c program is run, the LED starts to flash. Since I do not have a command for flashing the LED, I am not sure what is causing the LED to flash on P0. Yes, I am using SimpleIDE, hopefully someday that will get an update.

Since the FLiP module does not have an ADC option, I am experimenting with a Micromite processor, since it has six ADC pins to play with. I am also very sure that I can make a serial connection to the Micromite to get access to the ADC readings, which will than be available to view in the html code.
Next thing will be to add an SD breakout, for data logging, and a temp/humidity module, of some kind.

Ray
/*
  px1_flip.c

  May 11, 2018
  
  Parallax FLiP module with a WX WiFi SIP module attached to create a battery powered, stand
  alone remote base unit that is accessed via px1_flip.html.
  -Wish list: The FLiP module having four ADC pins available.
  
  -Ver .01:
    Base unit running an internet up-dateable softRTC via px1_flip.html.
 
*/
#include "simpletools.h"
#include "wifi.h"
#include "datetime.h"

/* softRTC */
datetime dt = {2018, 1, 1, 0, 0, 0};
char dates[9];
char times[9];
int day,month,year;
int hour,minutes,seconds;
/**********/

/* WiFi */
int event, id, handle;
int getFromPageId;
char cmdStr[64];
char *path;
/**********/

/* Function declaration */
void CRgetTime();
/**********/

int main()
{
  // Add startup code here.
  dt_run(dt);  // Start softRTC
  pause(150);
  wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
  pause(150);
  getFromPageId = wifi_listen(HTTP, "/tpfm*");  // WiFi
  
  
  while(1)
  {
    // Add main loop code here.
    wifi_poll(&event, &id, &handle);
    if(event == 'G')
    {
      if(id == getFromPageId)
      {
        /* Expansion of GET functionality */
        memset(cmdStr, 0, sizeof(cmdStr));
        sprint(cmdStr, "PATH:%d\r", handle);
        path = wifi_command(cmdStr);
        
        if(strstr(path, "/diag") !=0)
        {
          CRgetTime();  // Get the time and date
          wifi_print(GET, handle, "%s  - %s", dates,times);
        }
        //else if()
        //{
        //}                    
      }        
    }
    
    if(event == 'P')
    {
      if(id == getFromPageId)
      {
        /* Expansion of POST functionality */
        memset(cmdStr, 0, sizeof(cmdStr));
        sprint(cmdStr, "PATH:%d\r", handle);
        path = wifi_command(cmdStr);
        
        if(strstr(path,"/datetime") !=0)
        {
          wifi_scan(POST, handle, "month%d%d%d%d%d%d",&month,&day,&year,&hour,&minutes,&seconds);
          dt.y=year;
          dt.mo=month;
          dt.d=day;
          dt.h=hour;
          dt.m=minutes;
          dt.s=seconds;
          dt_set(dt);
        }
        //else if()
        //{
        //}                    
      }        
    }
    pause(50);                 
  }  
}
/**********/

/* Functions */
void CRgetTime()
{
  dt = dt_get();
  dt_toTimeStr(dt, times);
  dt = dt_get();
  dt_toDateStr(dt, dates);
}  


/**********/


px1_flip.html
<!-- px1_flip.html -->
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      a{
        background-color:#637aad;
        color:white;
	   font-size:23px;
	   margin:5px;
	   width:100px;
	   height:55px;
	   cursor:pointer;
	   padding-top:4px;
	   padding-bottom:4px;
      }
      a:hover{background-color:white;color:navy;}
    </style>
  </head>

  <body bgcolor=3b5898>
     <br>
	<br>
	<br>
	<font face="Arial" size=3 color="cyan">
     <a onclick="datetimeBtn()">DateTime</a> -- Update softRTC
     <br>
     <br>
     <br>
     <a onclick = "getFromMcu('diag')">Firmware</a> -- Check FLiP module firmware
	<font face="Arial" size=5 color="cyan">
     <p id = "value">Wating...</p>
	
   </body>

<script>
var getPathExt;

function useMcuReply(response)
{
	if(getPathExt = 'diag')
	{
	var val = document.getElementById("value");
	val.innerHTML = "Value: " + response;
	}
}

function getFromMcu(pathExt)
{
	getPathExt = pathExt;
	httpGet("/tpfm/" + pathExt, 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("Wating...");
	}
	req.send(null);
}
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 datetimeBtn()
{
	var dt = new Date();
	day = dt.getDate();
	
	var dt1 = new Date();
	month = dt1.getMonth();
	month = month +1;
	
	var dt2 = new Date();
	year = dt2.getFullYear();
	
	var dt3 = new Date();
	var hours = dt3.getHours();
	
	var dt4 = new Date();
	var minutes = dt4.getMinutes();
	
	var dt5 = new Date();
	var seconds = dt5.getSeconds();

	var send = "month=" + month + "day=" + day + "year=" + year + "hour=" + hours + "minutes=" + minutes + "seconds=" + seconds;
	httpPost("/tpfm/datetime",send);
}
</script>
</html>

Comments

  • 7 Comments sorted by Date Added Votes
  • A schematic drawing would help. When you wired up the FLiP module did you accidentally switch P0 with P31, or maybe a stray wire, or ???
  • I double checked the wiring on the breadboard, and everything looks OK. I also moved the LED connection to P1, that connection is not affected. When I move the connection back to P0, then the LED starts flashing.

    Since I have a pause() in the main() while(1) loop, if I increase or decrease the time, in the pause(), it shows up in the LED flashing cycle. Now I am wondering if there is something in the wifi_poll() function that is affecting P0?

    A brief overview, I have the WX module set for STA+... mode, so I can place the mobile base unit within a wifi signal range to gain access to it. At the moment when I start the program it starts the softRTC and then from a browser I can have the clock updated and view the results. Once I work out the install and connect to the Micromite, I will be able to view the battery voltage, in the html browser app.

    Ray
  • mparkmpark Posts: 1,165
    Comment out the wifi_poll call and see if the LED still flashes. Incrementally comment out more code until the LED doesn't flash.
  • First I commented out wifi_poll(), with a new run the LED turned on briefly and then turned off. I then uncommented wifi_poll() and I commented out the actual wifi_start(), then the LED remained off.

    So it looks like it might be something in the wifi_start() function that is affecting P0. Adding a low(0) right after the wifi_start() did not help, the LED keeps on flashing. It does not help if I put a low(0) right after the wifi_poll(), either. I am now wondering if some of the other pins are being affected, since I tried P1, I know that is not affected, at least it is not setting the pin high.


    Ray
  • mparkmpark Posts: 1,165
    wifi_start does bring the DI pin low briefly. According to your C code, that should be p30, not p0.

    Does the LED light up when p0 is low or when it's high? You say it flashes, but can you be more specific? E.g., "on for a second, off for a second, repeatedly" or "flickers multiple times a second for two seconds, then off for a second"--something along those lines?

    Maybe do some experiments with different pins in the second argument to your wifi_start() call.
  • Below is the program at its most basic form, easier to test. The way the program runs, at start up the LED P0 stays on for about a second, then it starts to blink at a pause(250) loop.

    Now, either my FLiP module has a problem with P0, or the problem is within wifi_start() and wifi_poll() functions. I am now hoping that somebody with a FLiP + WX wifi module(s) set can duplicate the problem. I also checked P1-P25, those pins do not blink the LED, so I will assume that that is OK.

    I am probably going to start coding to see if I can set up a decent communication between the FLiP and the Micromite. I want to do some data logging of battery functionality, and be able to see what the battery charge is at. Since the li-ion battery Ah is only 2.6 Ah, I need to know how long it can run before it needs a battery charge.

    Ray
    /*
      test2.c
      
      May 17, 2018
    */
    #include "simpletools.h"
    #include "wifi.h"
    
    int event, id, handle;
    int getFromPageId;
    
     
    int main()
    {
      // Add startup code here.
      wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
      //pause(150);
      //getFromPageId = wifi_listen(HTTP, "/tpfm*");  // WiFi
    
    
      while(1)
      {
        // Add main loop code here.
     
        wifi_poll(&event, &id, &handle);
        /*if(event == 'G')
        {
          
        }
        
        if(event == 'P')
        {
          
        }*/
        pause(250);           
      }  
    }
    
  • Wifi handle is the wrong type and you are not saving the handle returned by wifi_start( )
    /* WiFi */
    int event, id, handle;
    

    and
    int main()
    {
      // Add startup code here.
      wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
    




    Should be:
    int event, id;
    fdserial *handle
    

    and
    int main()
    {
      // Add startup code here.
      handle = wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
    
Sign In or Register to comment.