Mikroserver with PIC18F67J60 microcontroller.
PIC18F67J60 is a 8-bit microcontroller with large FLASH size (128 kB) and integrated Ethernet controller/PHY similar or identical to ENC28J60.
Firmware I used is Microchip TCP/IP stack modified by Jorge Amodio. Since I didn't connected external EEPROM to microcontroller MPFS_USE_EEPROM macro should not be defined and webpage files should be placed in internal FLASH memory (look at "Building the code image" chapter on Jorge Amodio page).
Additional link (it seems like ljcv.net is under reconstruction): http://www.ljcv.net/library/en/en002b.pdf.
PIC18F67J60 microserver scheme (pdf)
2010.05.05: Increased capacitors values at VCAP pin, datasheet recommends min. 1uF, typ. 10uF (total). PCB packages were not changed (0805), you may want to change them to 1206 as 1 uF, 4.7uF or 10uF 1206 capacitors might be easier to get that 0805 (e.g. scavenged from old PC motherboard).
PIC18F67J60 microserver scheme + PCB (Eagle Light)
Eagle (5.0) library with Pulse H1102 transformer (1:1, central tap)
Pulse H1102 transformer Other suggested transformers
Pickit 2, ICD2 or similar programmer is required. This microcontroller is not supported by popular simple JDM or COM84 programmers connected to serial port.
- "The Flash cells for program memory are rated to last 100 erase/write cycles". Typical number is 1000 according to datasheet.
- Ethernet module current consumption: max. 214 mA during transmission - chip can get quite hot; there may be small radiator needed on serial voltage regulator if supply voltage is over 6V. You can also connect few diodes in series to lower voltage.
Device is currently working as "thermometer" with temperature, relative humidity and pressure sensors.
Project source code (MPLAB 8.14 + C18): MCHPTCP_v126.96.36.199z.
MPLAB using absolute path to build tools, so it will probably ask to change them when opening project.
Measurement data is sent back when connecting to TCP 7777 port and is stored periodically to database through php script. You have to configure HTTP client - tcp_client_ex1.c changing target host (some_host.com) and target php file (hidden.php) to send POST request:
BYTE ServerName = "www.some_host.com"; WORD ServerPort = 80; BYTE httpPost1 = "POST /hidden.php HTTP/1.0\r\n"\ "Host: some_host.com\r\n" "Content-type: application/x-www-form-urlencoded\r\n" "Content-length: ";
Example php script to store data to database:
<?php $string=$_POST['s']; connect_to_database(); // replace with your code $n = sscanf($string, "Temp: %fC RH: %d%% %dhPa", $temperature, $humidity, $pressure); $result = mysql_query("insert into logi_temp (temp,czas) values('$temperature',NOW())",$db); if (result) $result = mysql_query("insert into logi_rh (rh,czas) values('$humidity',NOW())",$db); if (result) $result = mysql_query("insert into logi_pressure (pressure,czas) values('$pressure',NOW())",$db); ?>
Php code can be tested with curl:
curl --data-urlencode "s=Temp: -3.4C RH: 81% 1021hPa" www.tomeko.net/hidden.php
Currently microserver does not use urlencode function (laziness) sending equivalent of:
curl -d "s=Temp: -3.4C RH: 81% 1021hPa" www.tomeko.net/hidden.php
To avoid potential problems with some http servers either add urlencode function or use request that does not require it.
Update: I would recommend changing source port in dns.c, line MySocket = UDPOpen(0, &Remote, DNS_PORT); to other value that zero (and not conflicting with other source ports used in project). Leaving default value may result in random DNS client failure.