<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=10716&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-02-20T22:39:47+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=10716&amp;mode</id>
<entry>
<author><name><![CDATA[asek5]]></name></author>
<updated>2015-02-20T22:39:47+01:00</updated>
<published>2015-02-20T22:39:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=120141#p120141</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=120141#p120141"/>
<title type="html"><![CDATA[Re: enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=120141#p120141"><![CDATA[
Witam <br />Może to coś pomoże <a href="http://forum.atnel.pl/topic4294.html"  class="postlink">http://forum.atnel.pl/topic4294.html</a>.<br />Ja wolę wysyłać polecenia do serwera PHP i analizować odpowiedzi w atmedze. Szkoda że jako HOST nie można podać adresu IP.<br />Powodzenia z programem.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=5515">asek5</a> — 20 lut 2015, o 22:39</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jacky_cy]]></name></author>
<updated>2015-02-19T12:34:11+01:00</updated>
<published>2015-02-19T12:34:11+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119840#p119840</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119840#p119840"/>
<title type="html"><![CDATA[Re: enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119840#p119840"><![CDATA[
Pewnie, rozumiem <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /> i tak wielkie dzięki za wskazówkę z tym client www !<br />Aczkolwiek może ktoś z innych Kolegów poradzi z tym <br />make: *** [clientwww.elf] Error 1clientwww...<br />Jakby mi się udało coś stworzyć z tą stronką w php to efektami też się podzielę...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=4547">jacky_cy</a> — 19 lut 2015, o 12:34</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2015-02-19T12:22:25+01:00</updated>
<published>2015-02-19T12:22:25+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119839#p119839</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119839#p119839"/>
<title type="html"><![CDATA[Re: enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119839#p119839"><![CDATA[
Ja na tym etapie nie jestem w stanie tego analizować - przykro mi, chyba że ktoś pomoże kto się tym już bawił albo bawi ...<br /><br />Tymczasem niedługo ukaże się poradnik jak realizować skrypty PHP ale bez żadnego stosu w procku, wszystko za pomocą RS232 no i modułu ATNEL-WIFI232-T. I na tym na razie muszę się skupić.<br /><br />Podpowiem ci tylko że na tuxgraphics masz przykłady z tym klientem www, chociaż oni tam odpalają skrypty cgi a nie php no ale to na jedno i to samo wychodzi tak na prawdę z punktu widzenia procka<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 19 lut 2015, o 12:22</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jacky_cy]]></name></author>
<updated>2015-02-19T12:19:43+01:00</updated>
<published>2015-02-19T12:19:43+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119838#p119838</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119838#p119838"/>
<title type="html"><![CDATA[Re: enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119838#p119838"><![CDATA[
Wielkie dzięki za odpowiedź. Więc wziąłem sobie na warsztat tenże kod:<br /><br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />// http://www.nongnu.org/avr-libc/changes-1.8.html:<br />#define __PROG_TYPES_COMPAT__<br />#include &lt;avr/pgmspace.h&gt;<br />#include &quot;ip_arp_udp_tcp.h&quot;<br />#include &quot;websrv_help_functions.h&quot;<br />#include &quot;enc28j60.h&quot;<br />//#include &quot;../timeout.h&quot;<br />#include &quot;net.h&quot;<br />#include &quot;dnslkup.h&quot;<br /><br />// Please modify the following lines. mac and ip have to be unique<br />// in your local area network. You can not have the same numbers in<br />// two devices:<br />static uint8_t mymac&#91;6&#93; = {0x54,0x55,0x58,0x10,0x00,0x29};<br />// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX<br />// This web server's own IP.<br />//static uint8_t myip&#91;4&#93; = {10,0,0,29};<br />static uint8_t myip&#91;4&#93; = {192,168,0,110};<br />//<br />// The name of the virtual host which you want to<br />// contact at websrvip (hostname of the first portion of the URL):<br />#define WEBSERVER_VHOST &quot;tuxgraphics.org&quot;<br />// listen port for tcp/www:<br />#define MYWWWPORT 80<br /><br />// Default gateway. The ip address of your DSL router. It can be set to<br />// the same as the web server in the case where there is no default GW to access the<br />// web server (=web server is on the same lan as this host)<br />static uint8_t gwip&#91;4&#93; = {192,168,0,1};<br />//<br />// --- there should not be any need to changes things below this line ---<br />#define TRANS_NUM_GWMAC 1<br />static uint8_t gwmac&#91;6&#93;;<br />static uint8_t otherside_www_ip&#91;4&#93;; // will be filled by dnslkup<br />//<br />static char urlvarstr&#91;21&#93;;<br />//<br />//<br />#define BUFFER_SIZE 650<br />static uint8_t buf&#91;BUFFER_SIZE+1&#93;;<br />static uint8_t pingsrcip&#91;4&#93;;<br />static uint8_t start_web_client=0;<br />static uint8_t web_client_attempts=0;<br />static uint8_t web_client_sendok=0;<br />static volatile uint8_t sec=0;<br />static volatile uint8_t cnt2step=0;<br />static int8_t dns_state=0;<br />static int8_t gw_arp_state=0;<br /><br />// set output to VCC, red LED off<br />#define LEDOFF PORTD|=(1&lt;&lt;PORTD4)<br />// set output to GND, red LED on<br />#define LEDON PORTD&amp;=~(1&lt;&lt;PORTD4)<br />// to test the state of the LED<br />#define LEDISOFF PORTD&amp;(1&lt;&lt;PORTD4)<br />//<br /><br />uint16_t http200ok(void)<br />{<br />        return(fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n&quot;)));<br />}<br /><br /><br />// prepare the webpage by writing the data to the tcp send buffer<br />uint16_t print_webpage(uint8_t *buf)<br />{<br />        uint16_t plen;<br />        char vstr&#91;17&#93;;<br />        uint8_t err;<br />        plen=http200ok();<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;&lt;h2&gt;web client status&lt;/h2&gt;\n&lt;pre&gt;\n&quot;));<br />        if (gw_arp_state==1){<br />                plen=fill_tcp_data_p(buf,plen,PSTR(&quot;waiting for GW &quot;));<br />                mk_net_str(vstr,gwip,4,'.',10);<br />                plen=fill_tcp_data(buf,plen,vstr);<br />                plen=fill_tcp_data_p(buf,plen,PSTR(&quot; to answer arp.\n&quot;));<br />                return(plen);<br />        }<br />        if (dns_state==1){<br />                plen=fill_tcp_data_p(buf,plen,PSTR(&quot;waiting for DNS answer.\n&quot;));<br />                err=dnslkup_get_error_info();<br />                plen=fill_tcp_data_p(buf,plen,PSTR(&quot;Error code: &quot;));<br />                itoa(err,vstr,10);<br />                plen=fill_tcp_data(buf,plen,vstr);<br />                plen=fill_tcp_data_p(buf,plen,PSTR(&quot; (0=no error)\n&quot;));<br />                return(plen);<br />        }<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;Number of data uploads started by ping: &quot;));<br />        // convert number to string:<br />        itoa(web_client_attempts,vstr,10);<br />        plen=fill_tcp_data(buf,plen,vstr);<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;\nNumber successful data uploads to web: &quot;));<br />        // convert number to string:<br />        itoa(web_client_sendok,vstr,10);<br />        plen=fill_tcp_data(buf,plen,vstr);<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;\ncheck result: &lt;a href=http://tuxgraphics.org/cgi-bin/upld&gt;http://tuxgraphics.org/cgi-bin/upld&lt;/a&gt;&quot;));<br />        plen=fill_tcp_data_p(buf,plen,PSTR(&quot;\n&lt;/pre&gt;&lt;br&gt;&lt;hr&gt;&quot;));<br />        return(plen);<br />}<br /><br />/* setup timer T2 as an interrupt generating time base.<br />* You must call once sei() in the main program */<br />void init_cnt2(void)<br />{<br />cnt2step=0;<br />//PRR&amp;=~(1&lt;&lt;PRTIM2); // write power reduction register to zero<br />TIMSK=(1&lt;&lt;OCIE1A); // compare match on OCR2A<br />TCNT1=0;  // init counter<br />OCR1A=244; // value to compare against<br />TCCR1A=(1&lt;&lt;WGM12); // do not change any output pin, clear at compare match<br />// divide clock by 1024: 12.5MHz/128=12207 Hz<br />TCCR1B=(1&lt;&lt;CS12)|(1&lt;&lt;CS10); // clock divider, start counter<br />// 12207/244=50Hz<br />}<br /><br />// called when TCNT2==OCR2A<br />// that is in 50Hz intervals<br />ISR(TIMER1_COMPA_vect){<br />cnt2step++;<br />if (cnt2step&gt;50){<br />                cnt2step=0;<br />                sec++; // stepped every second<br />}<br />}<br /><br />// we were ping-ed by somebody, store the ip of the ping sender<br />// and trigger an upload to http://tuxgraphics.org/cgi-bin/upld<br />// This is just for testing and demonstration purpose<br />void ping_callback(uint8_t *ip){<br />        uint8_t i=0;<br />        // trigger only first time in case we get many ping in a row:<br />        if (start_web_client==0){<br />                start_web_client=1;<br />                // save IP from where the ping came:<br />                while(i&lt;4){<br />                        pingsrcip&#91;i&#93;=ip&#91;i&#93;;<br />                        i++;<br />                }<br />        }<br />}<br /><br />// the __attribute__((unused)) is a gcc compiler directive to avoid warnings about unsed variables.<br />void browserresult_callback(uint16_t webstatuscode,uint16_t datapos __attribute__((unused)), uint16_t len __attribute__((unused))){<br />        if (webstatuscode==200){<br />                web_client_sendok++;<br />                LEDOFF;<br />        }<br />}<br /><br />// the __attribute__((unused)) is a gcc compiler directive to avoid warnings about unsed variables.<br />void arpresolver_result_callback(uint8_t *ip __attribute__((unused)),uint8_t transaction_number,uint8_t *mac){<br />        uint8_t i=0;<br />        if (transaction_number==TRANS_NUM_GWMAC){<br />                // copy mac address over:<br />                while(i&lt;6){gwmac&#91;i&#93;=mac&#91;i&#93;;i++;}<br />        }<br />}<br /><br />int main(void)<br />{<br /><br /><br />        uint16_t dat_p,plen;<br />        char str&#91;20&#93;;<br /><br />        // Set the clock speed to &quot;no pre-scaler&quot; (8MHz with internal osc or<br />        // full external speed)<br />        // set the clock prescaler. First write CLKPCE to enable setting<br />        // of clock the next four instructions.<br />        // Note that the CKDIV8 Fuse determines the initial<br />        // value of the CKKPS bits.<br />       // CLKPR=(1&lt;&lt;CLKPCE); // change enable<br />      //  CLKPR=0; // &quot;no pre-scaler&quot;<br />        _delay_loop_1(0); // 60us<br /><br />        /*initialize enc28j60*/<br />        enc28j60Init(mymac);<br />       // enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz<br />        _delay_loop_1(0); // 60us<br /><br />        init_cnt2();<br />        sei();<br /><br />        /* Magjack leds configuration, see enc28j60 datasheet, page 11 */<br />        // LEDB=yellow LEDA=green<br />        //<br />        // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit<br />        // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);<br />        enc28j60PhyWrite(PHLCON,0x476);<br /><br />        DDRD|= (1&lt;&lt;DDD1); // LED, enable PB1, LED as output<br />        LEDOFF;<br /><br />        //init the web server ethernet/ip layer:<br />        init_udp_or_www_server(mymac,myip);<br />        www_server_port(MYWWWPORT);<br /><br />        // register to be informed about incomming ping:<br />        register_ping_rec_callback(&amp;ping_callback);<br /><br />        while(1){<br />                // handle ping and wait for a tcp packet<br />                plen=enc28j60PacketReceive(BUFFER_SIZE, buf);<br />                dat_p=packetloop_arp_icmp_tcp(buf,plen);<br />                if(plen==0){<br />                        // we are idle here trigger arp and dns stuff here<br />                        if (gw_arp_state==0){<br />                                // find the mac address of the gateway (e.g your dsl router).<br />                                get_mac_with_arp(gwip,TRANS_NUM_GWMAC,&amp;arpresolver_result_callback);<br />                                gw_arp_state=1;<br />                        }<br />                        if (get_mac_with_arp_wait()==0 &amp;&amp; gw_arp_state==1){<br />                                // done we have the mac address of the GW<br />                                gw_arp_state=2;<br />                        }<br />                        if (dns_state==0 &amp;&amp; gw_arp_state==2){<br />                                if (!enc28j60linkup()) continue; // only for dnslkup_request we have to check if the link is up.<br />                                sec=0;<br />                                dns_state=1;<br />                                dnslkup_request(buf,WEBSERVER_VHOST,gwmac);<br />                                continue;<br />                        }<br />                        if (dns_state==1 &amp;&amp; dnslkup_haveanswer()){<br />                                dns_state=2;<br />                                dnslkup_get_ip(otherside_www_ip);<br />                        }<br />                        if (dns_state!=2){<br />                                // retry every minute if dns-lookup failed:<br />                                if (sec &gt; 60){<br />                                        dns_state=0;<br />                                }<br />                                // don't try to use web client before<br />                                // we have a result of dns-lookup<br />                                continue;<br />                        }<br />                        //----------<br />                        if (start_web_client==1){<br />                                LEDON;<br />                                sec=0;<br />                                start_web_client=2;<br />                                web_client_attempts++;<br />                                mk_net_str(str,pingsrcip,4,'.',10);<br />                                urlencode(str,urlvarstr);<br />                                client_browse_url(PSTR(&quot;/cgi-bin/upld?pw=sec&amp;pingIP=&quot;),urlvarstr,PSTR(WEBSERVER_VHOST),&amp;browserresult_callback,otherside_www_ip,gwmac);<br />                        }<br />                        // reset after a delay to prevent permanent bouncing<br />                        if (sec&gt;60 &amp;&amp; start_web_client==2){<br />                               start_web_client=0;<br />                        }<br />                        continue;<br />                }<br />                if(dat_p==0){ // plen!=0<br />                        // check for incomming messages not processed<br />                        // as part of packetloop_arp_icmp_tcp, e.g udp messages<br />                        udp_client_check_for_dns_answer(buf,plen);<br />                        continue;<br />                }<br /><br />                if (strncmp(&quot;GET &quot;,(char *)&amp;(buf&#91;dat_p&#93;),4)!=0){<br />                        // head, post and other methods:<br />                        //<br />                        // for possible status codes see:<br />                        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html<br />                        dat_p=http200ok();<br />                        dat_p=fill_tcp_data_p(buf,dat_p,PSTR(&quot;&lt;h1&gt;200 OK&lt;/h1&gt;&quot;));<br />                        goto SENDTCP;<br />                }<br />                if (strncmp(&quot;/ &quot;,(char *)&amp;(buf&#91;dat_p+4&#93;),2)==0){<br />                        dat_p=http200ok();<br />                        dat_p=print_webpage(buf);<br />                        goto SENDTCP;<br />                }else{<br />                        dat_p=fill_tcp_data_p(buf,0,PSTR(&quot;HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n&lt;h1&gt;401 Unauthorized&lt;/h1&gt;&quot;));<br />                        goto SENDTCP;<br />                }<br />                //<br />SENDTCP:<br />                www_server_reply(buf,dat_p); // send data<br /><br />        }<br />        return (0);<br />}[/syntax]<br /><br />Tylko, że chciałem uruchomić ten program na ATmedze 32. Oprócz zmiany adresów IP, uznałem że trzeba również pozmieniać ustawienia timera więc oryginalny fragment:<br /><br />[syntax=c]void init_cnt2(void)<br />{<br />cnt2step=0;<br />PRR&amp;=~(1&lt;&lt;PRTIM2); // write power reduction register to zero<br />TIMSK2=(1&lt;&lt;OCIE2A); // compare match on OCR2A<br />TCNT2=0;  // init counter<br />OCR2A=244; // value to compare against<br />TCCR2A=(1&lt;&lt;WGM21); // do not change any output pin, clear at compare match<br />// divide clock by 1024: 12.5MHz/128=12207 Hz<br />TCCR2B=(1&lt;&lt;CS22)|(1&lt;&lt;CS21)|(1&lt;&lt;CS20); // clock divider, start counter<br />// 12207/244=50Hz<br />}<br /><br />// called when TCNT2==OCR2A<br />// that is in 50Hz intervals<br />ISR(TIMER2_COMPA_vect){<br />cnt2step++;<br />if (cnt2step&gt;50){<br />                cnt2step=0;<br />                sec++; // stepped every second<br />}<br />}[/syntax]<br /><br />zamieniłem na <br /><br />[syntax=c]void init_cnt2(void)<br />{<br />cnt2step=0;<br />//PRR&amp;=~(1&lt;&lt;PRTIM2); // write power reduction register to zero<br />TIMSK=(1&lt;&lt;OCIE1A); // compare match on OCR2A<br />TCNT1=0;  // init counter<br />OCR1A=244; // value to compare against<br />TCCR1A=(1&lt;&lt;WGM12); // do not change any output pin, clear at compare match<br />// divide clock by 1024: 12.5MHz/128=12207 Hz<br />TCCR1B=(1&lt;&lt;CS12)|(1&lt;&lt;CS10); // clock divider, start counter<br />// 12207/244=50Hz<br />}<br /><br />// called when TCNT2==OCR2A<br />// that is in 50Hz intervals<br />ISR(TIMER1_COMPA_vect){<br />cnt2step++;<br />if (cnt2step&gt;50){<br />                cnt2step=0;<br />                sec++; // stepped every second<br />}<br />}[/syntax]<br /><br />dodatkowo zakomentowałem :<br />[syntax=c]//CLKPR=(1&lt;&lt;CLKPCE); // change enable<br />      //  CLKPR=0; // &quot;no pre-scaler&quot;[/syntax]<br />oraz<br />[syntax=c]// enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz[/syntax]<br /><br />Problem w tym, że zawsze (próbowałem też programy z tuxgraphics np. z użyciem DS18B20) przy kompilacji wyrzuca mi:<br /><strong>make: *** [clientwww.elf] Error 1clientwww</strong><br /><br />Więc jakbym mógł prosić o jakąś wskazówkę co robię źle... <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=4547">jacky_cy</a> — 19 lut 2015, o 12:19</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2015-02-18T22:14:48+01:00</updated>
<published>2015-02-18T22:14:48+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119763#p119763</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119763#p119763"/>
<title type="html"><![CDATA[Re: enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119763#p119763"><![CDATA[
W stosie TCP z tuxgraphics masz w konfiguracji dostępne takie &quot;zwierzę&quot; jak &quot;client www&quot; ... to je właśnie trzeba zaprząc do roboty ...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 18 lut 2015, o 22:14</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[jacky_cy]]></name></author>
<updated>2015-02-18T21:48:45+01:00</updated>
<published>2015-02-18T21:48:45+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119759#p119759</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119759#p119759"/>
<title type="html"><![CDATA[enc28j60, udp i php]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10716&amp;p=119759#p119759"><![CDATA[
Witam,<br /><br />Więc.. na sam koniec niebieskiej książki Pana Mirka przerobiłem sobie rozdział o UDP. Programik TestyUDP też fajnie śmiga, lecz zamarzyłem sobie stworzenie stronki w php, która mogła by sobie odbierać ramki z wybranymi przeze mnie danymi. I moje pytanie wiąże się z tym czy mógłbym prosić o pomoc w nakierowaniu (jakiś link, podpowiedź) jak odebrać jakąś ramkę ze sterownika na stronce w php. <br /><br />Z góry bardzo dziękuję !<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=4547">jacky_cy</a> — 18 lut 2015, o 21:48</p><hr />
]]></content>
</entry>
</feed>