ETHERNET LIBRARY WITH WEB SERVER EXAMPLE FOR PIC18F97J60 FAM

General discussion on mikroBasic.
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#16 Post by yo2lio » 04 Jan 2008 01:06

Hi,

Sorry but example posted by me, It's OK and works ! Tested !

I can't give you assistance for HTML and JAVA !

The latest version is V3.3 and have source code in MikroPascal :
http://www.microelemente.ro/Eth_V3_3_Examples.zip
If you want you can rewrite this lib in MikroBasic.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

BarryP
Posts: 517
Joined: 02 Apr 2007 03:57
Location: New Zealand

#17 Post by BarryP » 04 Jan 2008 02:02

Sorry You missunderstood,
I wasn't asking for assistance.
Just sugesting a different method of update.
I.E.
This Is just a page you can save as html to test the AJAX.
after changeing MyLV18FJ_test_url of course.

Code: Select all

<html><head></head>
<body>
<script type="text/javascript">
   var MyLV18FJ_test_url = 'http://192.168.0.250/v_log.js';
   var xmlHttp;
   var starttime;

	 function RequestLogData(){
   	    starttime = new Date().getTime();
      	xmlHttp=GetXmlHttpObject();
      	if (xmlHttp==null){
        		alert ('Your browser does not support AJAX!');
        		return;}
      	xmlHttp.onreadystatechange=StateChange;
      	xmlHttp.open('GET',MyLV18FJ_test_url,true);
      	xmlHttp.send(null);}

   function GetXmlHttpObject(){
        var xmlHttp=null;
        	// Firefox, Opera 8.0+, Safari
        try {xmlHttp=new XMLHttpRequest();}catch (e){
          		// Internet Explorer first Test
        	try {xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');}catch (e)
          	// Internet Explorer second Test
        	{xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');}}
        return xmlHttp;}

   function StateChange(){
      	if(xmlHttp.readyState==4){
      	     addLogEntry(xmlHttp.responseText);
      	     setTimeout('RequestLogData()',3000);}}

   function addLogEntry(LogStr){
      	var req_time = new Date().getTime()-starttime;
      	if (LogStr=='') return;
      	var syslog = document.getElementById('txt_log');
          syslog.innerHTML+='<br>'+LogStr+'&nbsp;&nbsp; ::'  + req_time +' mSecs (very rough)';}
		        
	RequestLogData(); 
</script>
    
<fieldset>
	<legend>System Log</legend>
	<span id='txt_log'>System Log Loaded</span>
</fieldset><br>  
</body></html>

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#18 Post by yo2lio » 04 Jan 2008 08:49

Thanks !

Unfortunately my lib not support fragmentation, frame (page) must be under 1470 bytes.

I'll be very happy if someone implement fragmentation and TCP/IP STACK. Source code is available in MikroPascal.

Live software : http://ip-watcher.dyndns.info/ available for view 1 - 2 days.

This is Ip_Watcher based on Eth V3.3 library, commercial software/hardware.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#19 Post by yo2lio » 13 Jan 2008 21:09

Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#20 Post by yo2lio » 27 Jan 2008 17:36

Hi,

Ethernet library V3.3 for PIC18F97J60 family with examples are available here : http://www.microelemente.ro/MikroBasic/ ... amples.zip

Source code in Mikropascal : http://www.mikroe.com/forum/viewtopic.p ... 9&start=30

Default Ip : 192.168.1.253

Description :

Code: Select all

'Ethernet library V3.3 and example for PIC18F97J60.

' ARP, ICMP, UDP, NTP, TCP, HTTP

' Author of this project : Florin Andrei Medrea
' Copyright (c) 2008 - YO2LIO - All Rights Reserved
' 26-Jan-2008
 
User Functions and Procedures :

   
(AddrPacket is address of received packet, TXSTART is start address of transmited packet)

- Sub Procedure Eth_SetParameters
  ' Set your IP, Mac, Mask, Gateway ... etc... here.
  ' Str2Ip("192.193.194.14",eth_ip_addr)
  ' Str2Ip("85.120.220.254",eth_ntp_addr)
  ' Str2Ip("192.193.194.1",eth_gateway)
  ' Str2Ip("255.255.255.0",eth_mask)
  ' Str2Mac("0004A300809A",eth_mac)
  ' Str2Ip("192.193.194.4",user_ip_addr)
  ' eth_port = 10001
  ' dest_port = 10001

- Sub Procedure Eth_Init
  ' Init MCU Ethernet.

- Sub Procedure Eth_Reset
  ' Reset MCU Ethernet.

- Sub Procedure Wait_For_Lan
  ' Wait fo Lan Link.

- Sub Procedure Eth_DoPacket
  ' Process incoming packets.

- Sub Function Eth_UserTCP(dim byref dest_ip_addr_T as byte[4], dim byref source_port_T, dest_port_T, len_T as word) as word
  ' This function is called by library. Put your TCP response for WEB server parameters here. See example.

- Sub Function Eth_UserUDP(dim byref dest_ip_addr_U as byte[4], dim byref dest_port_U, source_port_U, len_U as word) as word
  ' This function is called by library. Put your UDP response here. See example. ( ECHO example )

- Sub Function CopyFlashToEthMem_CP(dim start_Flash_address as longint) as word
  ' Copy Const from flash to Eth Memory and return length of Const data.
  ' Const data must be defined as STRING. (and must be zero terminated)
  ' Ex. len = CopyFlashToEthMem_CP(@httpHeader)

- Sub Function Eth_SendARP(dim byref ip_dest as byte[4]) as Boolean
  ' Get ARP request. Return True if Mac exist.
  ' Return dest. mac address in dim dest_mac as byte[6].
  ' Return dest. ip address in dim dest_ip_addr as byte[4].
  ' Ex. bol = Eth_SendARP(user_ip_addr)
  ' First function search in ArpCache (size of 9) ...

- Sub Procedure SendUDP(dim dest_port_S, source_port_S, len_data as word, dim byref data_udp as array[1472] of byte)
  ' Send UDP mesage. Max 1472 bytes.
  ' Ex. If Eth_SendARP(user_ip_addr) then SendUDP(dest_port, eth_port, 10, 'Test Test ')

- Sub Procedure Eth_SendPing(dim SlotState as boolean, dim PingSlot as Byte)
  ' Have 8 Slots available 0 .. 7 and PingCache size of 8.
  ' Ex. Eth_SendPing(Eth_SendARP(user_ip_addr),0) Send Ping at user_ip_addr and put result in Slot 0.
  ' PingCache format as
  ' PingCache[Slot].IpP as byte[4]
  ' PingCache[Slot].MacP as byte[6]
  ' PingCache[Slot].Time as word
  ' PingCache[Slot].TTL as byte.

- Sub Function Send_Ping(dim byref ip_address as byte[4]) as word
  ' Send ping at specified ip_address and return response time.
  ' Ex. PingTimeResponse = Send_Ping(user_ip_address)

- Sub Function Send_UDP(dim byref ip_address as byte[4], dim dest_port_S, source_port_S, len_data as word, dim byref data_udp as array[1472] of byte) as boolean
  ' Send UDP mesage, max 1472 bytes, at specified ip_address and return true if success.
  ' Ex. Success = Send_UDP(user_ip_addr, 10001, 9999, 10, "data data ")

- Sub Function Send_ARP(dim byref ip_address as byte[4], dim byref mac_address as byte[6]) as boolean
  ' Get MAC for specified ip_address, put result in mac_address variable and return true if success.
  ' Ex. Success = Send_ARP(user_ip_addr,reply_mac_addr)

- Sub Procedure Firewall(dim ICMP, TCP, UDP as boolean)
  ' Default all false, allow all type of packets.
  ' If ICMP = true, ignore ICMP request. Ex. Firewall(true, false, false)
  ' If TCP = true, ignore TCP packets. Ex. Firewall(false, true, false)
  ' If UDP = true, ignore UDP packets. Ex. Firewall(false, false, true)
  
- Sub Function Ntp_query as Boolean
  ' Syncronize time.
  ' Ntp address must me stored in eth_ntp_addr (see Eth_SetParameters)
  ' If syncronization was successfully Ntp_sync flag will be true.

- Sub Procedure Get_Time
  ' Transform NTP time in day/month/year ...
  ' Data will be stored in as
  ' TTime.Rfc   = Time in RFC format
  ' TTime.Unix  = Time in UNIX format
  ' TTime.Year  = Year (ex. 2007)
  ' TTime.Month = Month (ex. 07)
  ' TTime.Day   = Day (ex. 31)
  ' TTime.Hour  = Hour(ex. 12)
  ' TTime.Min   = Min (ex. 59)
  ' TTime.Sec   = Sec (ex. 32)
  ' TTime.Str   = String format max. 32 ('2007-11-24 14:25:00')
  
- Sub Procedure Eth_PutByte(dim value as byte)
  ' Put one byte in ETH memory.

- Sub Function Eth_GetByte as byte
  ' Get one byte from ETH memory.

- Sub Procedure CopyEthMemToRam(dim start_eth_address, dest_ram_address, length_w as word)
  ' Ex. CopyEthMemToRam(AddrPacket+6,@dest_mac_addr,6)

- Sub Procedure CopyEthMemToRam_Inv(dim start_eth_address, dest_ram_address, length_w as word)
  ' Ex. CopyEthMemToRam(AddrPacket+6,@data_dWord,4)
  
- Sub Procedure CopyEthMemToEthMem(dim start_eth_address, dest_eth_address, length_w as word, dim where as byte)
  ' where = 0 copy from Eth RxBuf to Eth TxBuf
  ' where = 1 copy from Eth TxBuf to Eth TxBuf
  ' Ex. CopyEthMemToEthMem(AddrPacket+38,TXSTART+28,4,0)
  
- Sub Procedure CopyRamToEthMem(dim start_ram_address, dest_eth_address, length_w as word)
  ' Ex. CopyRamToEthMem(@eth_mac,TXSTART+22,6)

- Sub Procedure CopyRamToEthMem_Inv(dim start_ram_address, dest_eth_address, length_w as word)
  ' Ex. CopyRamToEthMem(@data_dWord,TXSTART+22,4)
  
- Sub Procedure CopyRamToEthMem_CP(dim start_ram_address, length_w as word)
  ' Copy var data to Eth Memory.
  ' Ex. CopyRamToEthMem_CP(@data,46)
  
- Sub Procedure CopyRamToEthMem_CP_Inv(dim start_ram_address, length_w as word)
  ' Ex. CopyRamToEthMem_CP(@data_dWord,4)
  
- Sub Function CopyRamStringToEthMem_CP(dim byref s as string[1472]) as word
  ' Copy var data to Eth Memory and return length of var data.
  ' Var data must be defined as String. (must be zero terminated)
  ' Ex. len = CopyRamStringToEthMem_CP('data data data')
  
- Sub Procedure CopyFlashToEthMem(dim start_Flash_address as longint, dim dest_eth_address, length_w as word)
  ' Ex. CopyFlashToEthMem(@httpHeader,TXSTART+54,30)

- Sub Procedure CopyFlashToEthMem_CP(dim start_Flash_address as longint, dim length_w as word)
  ' Ex. CopyFlashToEthMem(@httpHeader,30)

- Sub Function CopyFlashStringToEthMem(dim start_Flash_address as longint, dim dest_eth_address as word) as word
  ' Copy Const from flash to Eth Memory and return length of Const data.
  ' Const data must be defined as STRING. (must be zero terminated)
  ' Ex. len = CopyFlashToEthMem_CP(@httpHeader,TXSTART+54)
  
- Sub Function CopyFlashStringToEthMem_CP(dim start_Flash_address as longint) as word
  ' Copy Const from flash to Eth Memory and return length of Const data.
  ' Const data must be defined as STRING. (must be zero terminated)
  ' Ex. len = CopyFlashToEthMem_CP(@httpHeader)
  
- Sub Procedure WriteToEthMem(dim dest_eth_address as word, dim value as byte)
  ' Ex. WriteToEthMem(TXSTART+12,$08)

- Sub Function ReadFromEthMem(dim start_eth_address as word) as byte
  ' Ex. data = ReadFromEthMem(AddrPacket+38)

- Sub Function EthMemCompareWithRam(dim start_eth_address, start_ram_address, length_w as word) as boolean
  ' Ex. bol = EthMemCompareWithRam(AddrPacket+30,@eth_ip_addr,4)

- Sub Function EthMemCompareWithFlash(dim start_eth_address as word, dim start_Flash_address as longint, dim length_w as word) as boolean
  ' Ex. bol = EthMemCompareWithFlash(AddrPacket+54, @httpHeader, 30)
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#21 Post by yo2lio » 04 Feb 2008 22:44

Library and examples updated !

Resolved small BUG in CopyEthMemToEthMem routine. When length of data copy was 0 or 1, MCU frozen.
This BUG was submitted by guyfoc.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#22 Post by yo2lio » 08 Mar 2008 16:12

Hi,

Library updated. Resolved small bug in Get_Time routine.


You can download library from : http://www.microelemente.ro/MikroBasic/ ... amples.zip

Old files : http://www.microelemente.ro/MikroBasic/ ... es_old.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Rodan
Posts: 27
Joined: 15 Apr 2008 18:17

#23 Post by Rodan » 17 Apr 2008 18:18

Hi how do I change the initial IP adress of the LV card ethernet controller with one that is 192.168.0.x which is my private network?

Also how do i read the mac adress of the ethernet controller on board?

Is this program the same that is in the MikroeC examples?

thanks


Well it happear that I cant try it on the demo Basic because it give linker error: Demo limit

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#24 Post by yo2lio » 18 Apr 2008 14:14

You can do this in following procedure :

Code: Select all

Sub Procedure Eth_SetParameters   ' set your parameters here
  Str2Ip("192.168.1.253",eth_ip_addr) ' Put your IP here
  Str2Ip("192.168.1.1",eth_gateway) 'Put your gateway here
  Str2Ip("85.120.220.254",eth_ntp_addr) ' Put here a valid NTP address
  Str2Ip("255.255.255.0",eth_mask)
  Str2Mac("0004A3008080",eth_mac) ' Put your MAC here
  eth_port = 10001
  dest_port = 10001
  UpTime = 0
end sub
Is this program the same that is in the MikroeC examples?
No, is my library, designed for my applications and shared with Mikroe Forum Users.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Rodan
Posts: 27
Joined: 15 Apr 2008 18:17

#25 Post by Rodan » 18 Apr 2008 15:24

yo2lio wrote:You can do this in following procedure :

Code: Select all

Sub Procedure Eth_SetParameters   ' set your parameters here
  Str2Ip("192.168.1.253",eth_ip_addr) ' Put your IP here
  Str2Ip("192.168.1.1",eth_gateway) 'Put your gateway here
  Str2Ip("85.120.220.254",eth_ntp_addr) ' Put here a valid NTP address
  Str2Ip("255.255.255.0",eth_mask)
  Str2Mac("0004A3008080",eth_mac) ' Put your MAC here
  eth_port = 10001
  dest_port = 10001
  UpTime = 0
end sub
Is this program the same that is in the MikroeC examples?
No, is my library, designed for my applications and shared with Mikroe Forum Users.
Sorry but I am new on this, this code you posted is already insde the code in the example, but I cant compile it with the demo version it's to big because of the libraries.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#26 Post by yo2lio » 18 Apr 2008 16:44

Rodan wrote: Sorry but I am new on this, this code you posted is already insde the code in the example, but I cant compile it with the demo version it's to big because of the libraries.
:idea: You can not use this library without license ... Sorry ...
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Rodan
Posts: 27
Joined: 15 Apr 2008 18:17

#27 Post by Rodan » 18 Apr 2008 17:15

yo2lio wrote:
Rodan wrote: Sorry but I am new on this, this code you posted is already insde the code in the example, but I cant compile it with the demo version it's to big because of the libraries.
:idea: You can not use this library without license ... Sorry ...
Ok that make sense then, I am still figuring our what I should buy, so when i decided I will buy eiter Mebasic or Me C.

thanks
Experimenting on a LV 18FJ Board

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Web Server input state

#28 Post by arco » 09 May 2008 21:45

Hello,

I tested the Web Server code, and it works very nice! But I have one question:
Is it possible to make the status screen dynamic? I mean if I press an input switch, the state is updated on screen without having to press the refresh key?
Using MikroBasic
Regards,

Peter.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#29 Post by yo2lio » 10 May 2008 07:12

Hello !

My web server example have automatically refresh at 5000 ms.
This is defined in Java1 page, at the end :

Code: Select all

      "setInterval("+Chr(34)+"timer()"+Chr(34)+",5000);"
This example is designed and work correctly only under FIREFOX !!!
I don't know why don't work with Explorer.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

aftervillage
Posts: 13
Joined: 05 Jul 2007 14:55

#30 Post by aftervillage » 10 May 2008 08:36

Why not using the meta tag of html like:

<meta http-equiv="refresh" content="600">

put it in your head definition (before the body).

info from:
http://webdesign.about.com/od/metatagli ... 80300a.htm

setInterval is working for firefox and IE using this example from w3schools.com:
http://www.w3schools.com/js/tryit.asp?f ... etinterval
Cheers,
AfterVillage

Post Reply

Return to “mikroBasic General”