Plug and Program Dynamic Variables Source Code

an(n)

Purpose: Read an AD converter

Parameters: Analogue channel n (0-15)

Returns : return a raw value (0-1023)

Example : Read raw value of AD channel 1

~an(1)~

void HTTPPrint_an(WORD num)
{
	// PlugAndProgram.com 20110101
    BYTE AN0String[8];
    WORD ADval;
    // Determine which AN channel
    switch(num)
    {
        case 0:
            ADval = (WORD)ADC1BUF0;
            break;
        case 1:
            ADval = (WORD)ADC1BUF1;
            break;
        case 2:
            ADval = (WORD)ADC1BUF2;
            break;
        case 3:
            ADval = (WORD)ADC1BUF3;
            break;
        case 4:
            ADval = (WORD)ADC1BUF4;
            break;
        case 5:
            ADval = (WORD)ADC1BUF5;
            break;
        case 6:
            ADval = (WORD)ADC1BUF6;
            break;
        case 7:
            ADval = (WORD)ADC1BUF7;
            break;

        default:
            ADval = 0;
    }

    // Print the output
    uitoa(ADval, (BYTE*)AN0String);
    TCPPutString(sktHTTP, AN0String);
}

es(x)

Purpose: Read from PNP-ENVSENSE connected to MC32MX64GP.IO3

Parameters:

es(0) = Ambiant Light

es(1) = Temperature

es(2) = Barometric pressure

es(3) = Relative Humidity

Returns:

es(0) = an arbitrary light value

es(1) = Temperature in celcius

es(2) = Barometric pressure in kPa

es(3) = Percent relative humidity

Example: Read humidity

~es(3)~

void HTTPPrint_es1(WORD num)
{
	// PlugAndProgram.com 20110101
    BYTE AN0String[8];
    WORD ADval;

    // Determine which AN channel
    switch(num)
    {
        case 0:
            // Temperature MCP9700AT
            ADval = (DWORD)ADC1BUF1;
            ADval = (WORD)((WORD)((DWORD)( ADval /1024 ) *3300 ) - 500 ) / 10;
            // Print the output
            uitoa(ADval, (BYTE*)AN0String);
            TCPPutString(sktHTTP, AN0String);
            break;

        case 1:
            // Ambient light sensor
            ADval = (WORD)ADC1BUF0/100;
            // Print the output
            uitoa(ADval, (BYTE*)AN0String);
            TCPPutString(sktHTTP, AN0String);
            break;

        case 2:
            // MP3H6115A Pressure sensor
            ADval = (WORD)ADC1BUF2;
            //ADval = (((ADval / 1023) + 0.095 ) / 0.009);
            ADval = (WORD)(DWORD)(((ADval * 10000) / 1024 ) + 950 ) / 90;
            // Print the output
            uitoa(ADval, (BYTE*)AN0String);
            TCPPutString(sktHTTP, AN0String);
            break;

        case 3:

            // HIH-5030 Humidity Sensor
            ADval = (WORD)ADC1BUF3;
            ADval = (WORD)(DWORD)(((ADval * 100000) / 1024 ) - 15150 ) / 636;
            // Print the output
            uitoa(ADval, (BYTE*)AN0String);
            TCPPutString(sktHTTP, AN0String);
            break;

        default:
            ADval = 0;
            // Print the output
            uitoa(ADval, (BYTE*)AN0String);
            TCPPutString(sktHTTP, AN0String);
    }
}

ledh(x)

Purpose :  Read the current state of high (top row) LED0-7

Parameters: Target LED 0-7

Returns:

  • 1 (On)
  • 0 (Off)

Example: Read current state of high (top row) LED3

~ledh(3)~

void HTTPPrint_ledh(WORD num)
{
	// PlugAndProgram.com 20110101
	extern BYTE pnpLedH;
	TCPPut(sktHTTP, (((pnpLedH>>num)&1)== 1) ? '1': '0');
	return;
}

ledl(x)

Purpose :  Read the current state of low (bottom row) LED0-7

Parameters: Target LED 0-7

Returns:

  • 1 (On)
  • 0 (Off)

Example: Read current state of low (bottom row) LED3

~ledl(3)~

void HTTPPrint_ledl(WORD num)
{
	// PlugAndProgram.com 20110101
	extern BYTE pnpLedL;
	TCPPut(sktHTTP, (((pnpLedL>>num)&1)== 1) ? '1': '0');
	return;
}

ledmb

Purpose :  Read the current state of the mainboard onboard LED

Parameters: None

Returns:

  • 1 (High)
  • 0 (Low)

Example:

~ledmb~

void HTTPPrint_ledmb(void)
{
	// PlugAndProgram.com 20110101
	TCPPut(sktHTTP, (MBLEDTACTLAT?'1':'0'));
	return;
}

listfiles(x)

Purpose: lists contents of the MPFS2 filesystem image as hyperlinks

Parameters:

listfiles(e) lists contents of MPFS2 file system image stored on external memory

listfiles(i) lists contents of MPFS2 file system image stored on internal MCU ROM

Returns: A table of all files in the targeted MPFS2 file system image as click-able hyper-links

Example: List all files currently in the external memory

~listfiles(e)~

void HTTPPrint_listfiles(BYTE* source)
{
DWORD currentMPFSHandle;
BYTE fileName[64];
BYTE fileNameLen;

	// PlugAndProgram.com 20110101
	// Get name for every fatID from 0 up until we get a no reply
	// retrieve 1 fatID at a time
	// track next fatID in curHTTP.callbackPos
	// curHTTP.callbackPos is initialised at 00u for a new callback but needs to be other
	// than 0 for the callback to be treated as incomplete in the HTTP2 state SM_HTTP_SEND_FROM_CALLBACK
	// so we will use curHTTP.callbackPos to keep track of the next fatID as fatID + 1

	// We output an HTML A ref
	//	<a href="/filename">/filename</a></br>
	//	File names are 64 bits, so we need to ensure we have 10 + 63 + 3 + 63 + 9 = 148 chars
	// space in TCPPutArray before we output this entry

	if (curHTTP.callbackPos == 0)
	{
		// First time in listfiles for this callback
		curHTTP.callbackPos = 1;

		if(*source == 'I' || *source == 'i')
			{
			// List from internal memory
			curHTTP.callbackPos += INTERNALFATIDOFFSET;
			}
	}

	if (TCPIsPutReady(sktHTTP) > 148)
	{
		if ((currentMPFSHandle = MPFSOpenID(curHTTP.callbackPos - 1)) != MPFS_INVALID_HANDLE)
		{

			if (MPFSGetFilename(currentMPFSHandle, fileName, 64))
			{
				fileNameLen = strlen(fileName);
				// Len can be 0 if is MPFS2 file system dynamic variable index file
				if (fileNameLen > 0)
				{
					TCPPutArray(sktHTTP, "<a href=\"/", 10u);
					TCPPutArray(sktHTTP, fileName, fileNameLen);
					TCPPutArray(sktHTTP, "\">/", 3u);
					TCPPutArray(sktHTTP, fileName, fileNameLen);
					TCPPutArray(sktHTTP, "</a></br>", 9u);
				}
			}
			MPFSClose(currentMPFSHandle);
			curHTTP.callbackPos++;
		}
		else
		{
			// No more fatID's to process so close the callback
			curHTTP.callbackPos = 0;
		}
	}

	return;
}

ntpgmt

Purpose : Read the current NTP GMT time (if NTP servers available)

Parameters : None

void HTTPPrint_ntpgmt(void)
{
	DWORD time = SNTPGetUTCSeconds();
	// PlugAndProgram.com 20110101
	// Print the output if it has been received from NTP server
	TCPPutString(sktHTTP, (BYTE*) ctime(&time));
}

requestip

Purpose: Get the IP address of the end user requesting this page

Parameters: None

Returns: Ip Address

void HTTPPrint_requestip(void)
{
	SOCKET_INFO *remoteSockInfo;
	BYTE digits[4];
	BYTE i;
	// PlugAndProgram.com 20110222
	// Print the IP Address of the requestor
	remoteSockInfo = TCPGetRemoteInfo(sktHTTP);
	for(i = 0; i < 4u; i++) 	{ 		if(i) 			TCPPut(sktHTTP, '.'); 		uitoa(remoteSockInfo->remote.IPAddr.v[i], digits);
		TCPPutString(sktHTTP, digits);
	}
}

Updated 20110209