Pages: 1 [2]   Go Down
Author Topic: Xbee API ethernet problem HTML  (Read 1168 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I receive information of xbees so it comes in my code where i do'nt know...

Do you have the library avr/wdt for the arduino?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I meant something different. If you connect a PC to your Arduino (if they have XBees you probably have to use SoftwareSerial and a USB2Serial adapter) and insert debugging statements into your code that put some string to the soft serial after every bit of code. On the PC you log the output of that line and then you know in which part of your code the infinite loop (or whatever produces the freeze) occurs.

As for the watchdog, I know this tutorial page:

http://tushev.org/articles/electronics/48-arduino-and-watchdog-timer

I don't know where you need a library there because it needs just a few lines of code.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I will make it but I think the problem comes of the generation of the web page and of library ethernet because it works one time and then after error of page.

I will debug step by step not the choice..
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your assumptions may be right but even then you probably wanna know where the error occurs because it's easier to find if you know the region in the code where it stops.

What does "works one time and then after error of page" mean? Do you know the condition when it fails? Are you able to reproduce the failure?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It means that : The temperature displays on a page web and after few hours it does'nt display (error page). Then it can display again (without reset). Maybe it can come from the network which requests my arduino + ethernet shield in order to display a graph of these temperatures. I don't know.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like debbug my code with a LED for example so i would like to know where is the problem, on the readpacket (RS232) or on the ethernet web.
This is my code in readpacket :

Code:
void readpacket()
  {
  if (Serial.available() > 0)
    {
digitalWrite(LED,HIGH);
delay(1000);
    delayMax = millis()+50;
    int b = Serial.read();
    if (b == 0x7E)
      {
        packet[0] = b;                           
        packet[1] = readByte();
        packet[2] = readByte();
        int dataLength = (packet[1] << 8) | packet[2]; 
        for(int i=1;i<=dataLength;i++)
          {
            packet[2+i] = readByte();               
          }
        int apiID = packet[3];               
        if (apiID == 0x83)
            {

             
              moduleID[1] = (packet[4] << 8) | packet[5];
              if (moduleID[1]==0x01)
              {
                int SgnlPwr = packet[6];
                int SampleNumber = packet[8];                                                                                                                   
                int i;                                                                                                                                                                                                                                                                                                                                       
                if (SampleNumber >= 1) 
                  {                                                                                                       
                    analogSamples[1] = (packet[11] << 8) | packet[12];
                    analogSamples[2] = (packet[13] << 8) | packet[14];
                    analogSamples[3] = (packet[15] << 8) | packet[16];
                    analogSamples[4] = (packet[17] << 8) | packet[18];
                    delay(1);
                  }
                   int reading = analogSamples[1]; 
                   int reading_2 = analogSamples[2];
                   int reading_3 = analogSamples[3];
                   int reading_4 = analogSamples[4];
        // On converti la valeur lue  en millivolts
                   v[1] =((float) reading)*330/1024; 
                   v[2] =((float) reading_2)*330/1024;
                   v[3] =((float) reading_3)*330/1024;
                   v[4] =((float) reading_4)*330/1024;
                   delay(1);
              }
              else if (moduleID[1]==0x02)
              {
               int SgnlPwr = packet[6];
                int SampleNumber = packet[8];                                                                                                                   
                int i;                                                                                                                                                                                                                                                                                                                                       
                if (SampleNumber >= 1) 
                  {                                                                                                       
                    analogSamples[1] = (packet[11] << 8) | packet[12];
                    analogSamples[2] = (packet[13] << 8) | packet[14];
                    analogSamples[3] = (packet[15] << 8) | packet[16];
                    analogSamples[4] = (packet[17] << 8) | packet[18];
                    analogSamples[5] = (packet[19] << 8) | packet[20];
                    delay(1);
                   
                  }
                   int reading_5 = analogSamples[1]; 
                   int reading_6 = analogSamples[2];
                   int reading_7 = analogSamples[3];
                   int reading_8 = analogSamples[4];
                   int reading_9 = analogSamples[5];
        // On converti la valeur lue  en millivolts
                   z[1] =((float) reading_5)*330/1024; 
                   z[2] =((float) reading_6)*330/1024;
                   z[3] =((float) reading_7)*330/1024;
                   z[4] =((float) reading_8)*330/1024;
                   z[5] =((float) reading_9)*330/1024;
                   delay(1);
              }
              else if (moduleID[1]==0x03)
              {
               int SgnlPwr = packet[6];
                int SampleNumber = packet[8];                                                                                                                   
                int i;                                                                                                                                                                                                                                                                                                                                       
                if (SampleNumber >= 1) 
                  {                                                                                                       
                    analogSamples[1] = (packet[11] << 8) | packet[12];
                    analogSamples[2] = (packet[13] << 8) | packet[14];
                    analogSamples[3] = (packet[15] << 8) | packet[16];
                    analogSamples[4] = (packet[17] << 8) | packet[18];
                    analogSamples[5] = (packet[19] << 8) | packet[20];
                    delay(1);
                   
                  }
                   int reading_10 = analogSamples[1]; 
                   int reading_11 = analogSamples[2];
                   int reading_12 = analogSamples[3];
                   int reading_13 = analogSamples[4];
                   int reading_14 = analogSamples[5];
        // On converti la valeur lue  en millivolts
                   y[1] =((float) reading_10)*330/1024; 
                   y[2] =((float) reading_11)*330/1024;
                   y[3] =((float) reading_12)*330/1024;
                   y[4] =((float) reading_13)*330/1024;
                   y[5] =((float) reading_14)*330/1024;
                   delay(1);
              }
            }
             
      }
    }
else
{
digitalWrite(LED,LOW);
}
  }
 uint8_t readByte()
  {
    while (true)
      {
if(delayMax <= millis())
        {
            break;
        }
        if (Serial.available() > 0)
        {
          return Serial.read();
        }
      }
    return 0; 
  }

I put digitalWrite(LED, HIGH) if serial is available else LOW if serial is not available but it doesn't work... I don't know
I bought an other module ethernet ENC28J60...
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This code:

Code:
digitalWrite(LED,HIGH);
delay(1000);

is not a good idea. You wait for 1 second when you know that characters are waiting in the receive buffer of your serial interface. In 1 second almost 1000 characters may be transmitted, 95% of them will be lost because you're waiting doing nothing. After that you give 50ms to read the whole packet, which probably is enough if you don't wait before but so it doesn't make sense.

Code:
int dataLength = (packet[1] << 8) | packet[2]; 

I guess packet is defined a uint8_t array. If this is so, you won't get what you expected as packet[1] << 8 is always 0 (shifting all bits out).
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
int dataLength = (packet[1] << 8) | packet[2]; 

I guess packet is defined a uint8_t array. If this is so, you won't get what you expected as packet[1] << 8 is always 0 (shifting all bits out).

I removed the first packet and I kept that the second :

Code:
int b = Serial.read();
    if (b == 0x7E)
      {
        packet[0] = b;                           
        packet[1] = readByte();
        packet[2] = readByte();
        int dataLength = packet[2]; 
        for(int i=1;i<=dataLength;i++)
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If i want a reset device. Can I do this :

Code:
void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
  pinMode(RESET,OUTPUT);
  reset();
  delay(1);
}

void reset()
{
digitalWrite(RESET,LOW);
delay(50);
digitalWrite(RESET,HIGH);
delay(2000);
}

Can i put the function reset in setup like this the device every time resets?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you remove the delay(1000) too? If yes, what's the result?

Quote
Can i put the function reset in setup like this the device every time resets?

You can but usually the device is reset by hardware when the Arduino itself is reset and setup() is called only in this case. And remove the delay(2000) it's not necessary.
Logged

Pages: 1 [2]   Go Up
Jump to: