1. OCAU Merchandise now available! Check out our 20th Anniversary Mugs, Classic Logo Shirts and much more! Discussion here.
    Dismiss Notice

Silicon Chip Web Server In a Box kit

Discussion in 'Electronics & Electrics' started by Gecko, Feb 16, 2010.

  1. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,088
    Location:
    Sleepwithyourdadelaide
    That is the TRIS bit eg setting it to an output or input. You need to search for BUTTONx_IO, if you do that you will numerous entries.

    For example BUTTON0_IO is referenced in Telnet, PingDemo, LegacyHTTPApp, CustomSNMPApp, CustomHTTPApp

    The other buttons are referenced in most of those files including UDPPerformanceTest as well.
     
  2. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Ok, got it thanks :)

    Code:
    void setOutput(BYTE outputNum, BYTE action)
    {
    	switch(outputNum)
    	{
    		case 0:
    			if(action=='0')BUTTON0_IO=0; else if(action=='1')BUTTON0_IO=1; else BUTTON0_IO^=1;
    			break;
    		case 1:
    			if(action=='0')BUTTON1_IO=0; else if(action=='1')BUTTON1_IO=1; else BUTTON1_IO^=1;
    			break;
    		case 2:
    			if(action=='0')BUTTON2_IO=0; else if(action=='1')BUTTON2_IO=1; else BUTTON2_IO^=1;
    			break;
    		case 3:
    			if(action=='0')BUTTON3_IO=0; else if(action=='1')BUTTON3_IO=1; else BUTTON3_IO^=1;
    			break;
    		default:
    			break;
    	}
    }
    
    
     
  3. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,088
    Location:
    Sleepwithyourdadelaide
    Looks good to me!
     
  4. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Don't know if anyone is still playing with this, but a heads up to the people that were making their own PCBs for the project...
    The small surface mount EEPROM (25AA02E48) in the kit is an SPI serial EEPROM
    supplied with a globally unique MAC address.
    In the released kit, it is only used to provide the MAC address.

    This MAC address is included in the email the WIB sends to you when it powers up.
    Once you have it, you can write it into the dsPic's program memory so you
    no longer need the EEPROM chip at all, making it possible to design it out of the
    circuit board all together! :)

    At the moment, You need to be able to compile the source to do this,
    but I might be able to rework the source to store it on SD card.

    Code:
    // LOAD MAC Address from EEPROM routine commented out
    //
    //	XEEBeginRead(0x00FA);
    //	for(i=0; i<6; i++)
    //	{
    //    AppConfig.MyMACAddr.v[i]=XEERead();
    //	}
    //	XEEEndRead();
    
    
    // LOAD MAC Address Directly From Program Memory (Web Server Mod - Art 2010)
    AppConfig.MyMACAddr.v[0]=0xAA;
    AppConfig.MyMACAddr.v[1]=0xBB;
    AppConfig.MyMACAddr.v[2]=0xCC;
    AppConfig.MyMACAddr.v[3]=0xDD;
    AppConfig.MyMACAddr.v[4]=0xEE;
    AppConfig.MyMACAddr.v[5]=0xFF;
    
    
    Microchip provide the EEPROM for free as samples, so it isn't hard to come up with a few more unique MAC addresses.

    Cheers,
    Art.
     
    Last edited: Jun 13, 2010
  5. scorpia

    scorpia Member

    Joined:
    Sep 2, 2001
    Messages:
    344
    Location:
    Melbourne, 3805
    Im still trying to work out the point of this, why take a Gobally unique MAC address and use it elsewhere? why not just make up an address?

    or better still get more of the eeproms and add them to the board so that each board is unique, afterall that is the point of the chip
     
  6. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    The point is making the PCB a bit smaller and simpler.
    You can throw the EEPROM away once you read the MAC from it.
    Particularly useful to me since the EEPROM is the only chip not available in the DIP package.

    You still need to have the EEPROM in the first place to get the unique MAC address,
    but once you read it off, the MAC can be stored on the dspic instead of the EEPROM.

    I wasn't suggesting you'd use the same MAC in more than one Web Server unit.

    ... and if you made up a MAC, you couldn't be sure it was globally unique,
    and it wouldn't be licensed to prevent it being supplied to someone else later on.
     
  7. OP
    OP
    Gecko

    Gecko Member

    Joined:
    Jul 3, 2004
    Messages:
    2,715
    Location:
    Sydney
    As long as the device stays within your network, you can use any MAC you want to really

    As an aside, MACs don't end up globally unique every time... we had a few boxes delivered to work where 2 had the same MAC address - took a while to figure that one out!
     
  8. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    MACs should be globally unique.

    The first three bytes of all of our WIB MAC addresses are 00:04:A3 because that
    is the organisational identifier associated with Microchip.
    The last three bytes are generated by the factory.
    If they ever run out three byte combinations (still a possible 16777216 unique combinations)
    they need to arrange a new organisational identifier from a mob called the IEEE Registration Authority.

    I'd say for your case the manufacturer only purchased a certain amount of
    licensed MACs and reused some of them.

    I have just realised the best reason to ditch the EEPROM is that it's absence
    frees up an IO pin of the microcontroller.
    RB6 was connected directly to the Chip Select pin of the EEPROM,
    and if the EEPROM is removed, the pad for pin 1 directly connects to RB6 of the dsPic :)
    Handy since the WIB has no physical button inputs at all.
     
    Last edited: Jun 13, 2010
  9. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Might be time to hit up some of the guys for help again...

    I have implemented a Sunrise & Sunset calculation routine which is a
    stripped down version of this:
    http://personal.inet.fi/cool/jjlammi/rscalc.c
    which I have previously gotten working well on the Sony Playstation Portable.

    I've implemented a new dynamic page content code (~E4)
    allowing the Sunrise and Sunset times to be displayed on a web page.
    This can be seen on the server's index page if you can connect to my server:
    http://art.redirectme.net:8181/

    There is a little inaccuracy in the Sunset time compared to the routine running
    on my Sony PSP. The Sunset time for today is 17:08 on the PSP code, and 17:28 on
    the WIB code. Other than that all is fine... Sunrise is at 06:35 for both programs.

    What I'd like to sort out is reading some new settings from the SD card.

    The Sun times calc routine needs your location expressed as latitude and longitude (two floats).
    It also needs the time, date and timezone offset,
    but those values are already available from variables in the WIB's code.

    So did anyone read up enough to make new SD card setting fields or am I on my own??? :D

    Originally, this was just to turn on the LCD backlight at Sunset, and off again at Sunrise
    so I wasn't fussed about the small error in the routine... I still might spot it though.

    So right now I'd like to produce three new settings fields... Latitude (float), Longitude (float), and MAC (ASCII string of six bytes).
     
    Last edited: Jun 14, 2010
  10. OP
    OP
    Gecko

    Gecko Member

    Joined:
    Jul 3, 2004
    Messages:
    2,715
    Location:
    Sydney
    They SHOULD be, but do not NEED to be :)

    I'm just against buying the chips to simply chuck them in the bin when its not needed
     
  11. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    The chips can be ordered as free samples direct from Microchip.
    I've already had three sent to me, and read the MACs off them.
    I guess they can still be used as 2K EEPROMs.. just that in my own
    projects I'd opt for I2C EEPROMs.




    @ Foliage, Your PM box is full.

    Yes, everything else is working.
    It's just that at the moment, the MAC, latitude & longitude
    are hard coded into program memory.
    I'd like it if they were a setting in the settings.txt file.

    So far, I've found this in the file "common.h"
    #define SETTINGS_FILE "settings.txt"
    #define VALUES_FILE "values.dat"

    So I guess I'd start searching for instances of
    SETTINGS_FILE and VALUES_FILE.
    Admittedly, I haven't given this much time yet.
    Maybe I'll dig around a bit and ask for more specific help during the week.
     
  12. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,088
    Location:
    Sleepwithyourdadelaide
    Code:
    void getConstants(void)
    {
    	int i;
    	if((f_open(&fsrc, SETTINGS_FILE, FA_OPEN_EXISTING | FA_READ))==FR_OK)
    	{
    		while(1)
    		{
    		 if((getConfigFileLine(variableBuffer, valueBuffer, &fsrc, 80))==0)break;
    		 i=extractSetting(variableBuffer, valueBuffer, settingsNames);
    		}
    //		XEEBeginWrite(0x0000);
    //	    XEEWrite(0xFF);
    //		XEEEndWrite();
    	}
    	f_close(&fsrc);
    }
    
    void getValues(void)
    {
    	int i, n;
    	unsigned int u;
    
    	if((f_open(&fsrc, VALUES_FILE, FA_OPEN_EXISTING | FA_READ))==FR_OK)
    	{
    		i=0;
    		n=0;
    		while(1)
    		{
    			if(settingsNames[i].resultType==RESULT_NONE)break;
    			f_lseek(&fsrc, n);
    			f_read(&fsrc, valuesBuffer, 255, &u);
    			n+=(moveSetting(settingsNames[i].value, (BYTE*)valuesBuffer, settingsNames[i].resultType, WRITE_DIR));
    			i++;
    		}
    	} 
    	f_close(&fsrc);
    }
    
    
    Found this segment in MainDemo.c

    Looks like what you are looking for, those functions are called from within the function extractAllSettings() which is called during initialisation when the device is powered up

    Could quite easily duplicate one of these functions and load a separate file with your own settings, or just expand the standard settings.txt file to include your new settings, do it in a way that makes the files backwards compatible with the original firmware however.

    Will require a bit of reverse engineering and code digging to figure out how the settings are loaded and work, be a bit of work there but you should be able to quite easily figure it out and expand on it.
     
  13. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Thanks, unfortunately this long weekend is the first opportunity I've had
    for any programming really :( It's not that I've lost any enthusiasm with this project.

    I think I can make a bit more time during the week to look at this though,
    and maybe hit it hard again next weekend.
     
  14. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Originally meant as PM for Foliage, but yeah, your box is full again :D

    Hey Foliage,
    Had a little problem I though You'd be able to help with.
    ... re the C web server code again,
    It supports commands "MGET", "MPUT", etc,
    but I cannot find these commands referenced anywhere.
    "QUIT", "DELETE", etc are also supported, but Windows
    searches for words like that will yield results everywhere in the code.

    I can see code in FTP.c where the server acts on these commands,
    but no references to the commands themselves.
    They must be defined somewhere.

    .. Point is.. I want a few custom FTP commands to act on IO lines.
    The FTP server is far more reliable for me than the web server.

    Sp any pointers would be much appreciated.
    I've got other parts I can work with until I figure that out.
    Cheers, Art.
     
  15. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,088
    Location:
    Sleepwithyourdadelaide
    All the FTP commands are stored in

    static ROM char *FTPCommandString[]

    which is in FTP.c
    the array is only accessed in this function by the looks of it
    FTP_COMMAND ParseFTPCommand(BYTE *cmd);

    I would add your custom commands to the end of this array and put the processing code in this function:

    BOOL FTPServer(void)

    you should be able to figure out what the state machine in there is doing and put an if statement somewhere that checks the command, if it is what you want activate some IO lines etc.
     
  16. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    I can see this array:
    Code:
    static ROM char *FTPCommandString[] =
    {
        "USER",                         // FTP_CMD_USER
        "PASS",                         // FTP_CMD_PASS
        "QUIT",                         // FTP_CMD_QUIT
        "STOR",                         // FTP_CMD_STOR
    	"RETR",							// FTP_CMD_RETR			added by M.G.
    	"NLST",							// FTP_CMD_NLST			added by M.G.
    	"LIST",							// FTP_CMD_LIST			added by M.G.
    	"DELE",							// FTP_CMD_DELE			added by M.G.
        "PORT",                         // FTP_CMD_PORT
        "ABOR",                         // FTP_CMD_ABORT
        "PWD ",                         // FTP_CMD_PWD
    	"XPWD",							// FTP_CMD_PWD			added by M.G.
        "CWD ",                         // FTP_CMD_CWD
        "TYPE"                          // FTP_CMD_TYPE
    };
    But these words aren't used for the FTP server.
    For example "LIST" is an invalid command when typed into the FTP server.
    The List command is actualy "LS".
    and "MGET" & "MPUT" aren't in that table at all, but those commands do work.

    The full list of supported FTP commands:
    CD, PWD, DELETE, DIR, LS, PUT, GET, MPUT, MGET, USER, PASS, OPEN, QUIT.
     
  17. Cue Ball

    Cue Ball New Member

    Joined:
    Aug 5, 2010
    Messages:
    1
    Completely new, please help

    I have just finished building the SC web server in a box and it seems to work OK. I can access it from the LAN side, but it will not pick up the time client. I can't access it from the WAN side and no email. It is connected to my Siemens Speedstream 4200 modem (a Telstra special) via a T100 base hub. I have set the DHCP server range to exclude the WIB IP address, and I have enabled Port Forwarding. In the settings summary it shows that Ports 80 and 20 are forwarded to the correct address. Has anyone managed to get this going with this modem? If so, what am I doing wrong? Any help appreciated.
     
  18. Goth

    Goth Grumpy Member

    Joined:
    Jun 22, 2002
    Messages:
    9,228
    Location:
    /dev/null
    Cue Ball; I've merged your thread onto this existing thread on the subject.

    Cheers.
     
  19. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,088
    Location:
    Sleepwithyourdadelaide
    You have any luck with this in the end?
     
  20. @rt

    @rt Member

    Joined:
    Nov 30, 2005
    Messages:
    2,329
    Yes, but I can't add more commands because the Windows FTP client will only send certain commands.
    It won't do anything with commands I make up.

    Next strategy is to FTP a file with a known name and/or extension containing
    a list of output pins to change the state of, and a command to send an email
    containing the state of the analogue inputs, etc.

    Just haven't gotten a lot of time to play with it lately with work :(
     

Share This Page

Advertisement: