Pages: [1] 2   Go Down
Author Topic: Xbee API ethernet problem HTML  (Read 1058 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

Hello everybody,
I'm french and I come to you because I deployed a network of xbee ( Api) with sensors of temperature LM35DZ. Indeed, I use the analogical input of xbees to get back the various temperatures. Every room contains a xbee, in receiver I have another xbee which gets back all the packages of transmitters. To see the temperatures, I use an arduino + ethernet shield to convert its packages in decimal values and send it on a HTML page. The acquisition matches a small moment then at the end of a few days the HTML page does not generate any more (it stays in perpetual research). This stop is never at the same moment. It is variable

I modified my code in order to put the reset as soon as the system doesn't respond but unfortunetly it is not sufficient... I don't know where is the problem now. Maybe the reset code is badly programmed?

It is probably in the Ethernet library. I don't know...


Thanks you for your replies
Logged

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

This my code :

Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x14, 0x46 };
IPAddress ip(162,38,115, 28);


unsigned long delayMax = 0;

int packet[32];
int analogSamples[5];
int moduleID[1];
int RESET = 7;

float v[4];
float z[5];
float y[6];

EthernetServer server(80);

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

void loop()
{

  readpacket();
  EthernetClient client = server.available();
 
  if (client)
    {
       boolean currentLineIsBlank = true;
       while (client.connected())
         {
           if (client.available())
             {
               
               char c = client.read();
               if (c == '\n' && currentLineIsBlank)
                 {   
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println();
                   
                       
                        client.println(v[1]);
                        client.println(v[2]);
                        client.println(v[3]);
                        client.println(v[4]);
                        client.println();
                     
                       
                       client.println(z[1]);
                       client.println(z[2]);
                       client.println(z[3]);
                       client.println(z[4]);
                       client.println(z[5]);
                       client.println();
                     
                       
                       client.println(y[1]);
                       client.println(y[2]);
                       client.println(y[3]);
                       client.println(y[4]);
                       client.println(y[5]);
                       client.println();                                               
                  break;
                 }
             
             if (c == '\n')
               {
                 currentLineIsBlank = true;
               } 
               else if (c != '\r')
               {
                  currentLineIsBlank = false;
               }
             }
         
    }
    delay(500);
    // fermer la connection
    client.flush();
    client.stop();
    // faire un reset
    digitalWrite(RESET, LOW);
    }
 digitalWrite(RESET, LOW);
}

void readpacket()
  {
  if (Serial.available() > 0)
    {
    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];                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                     
                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];
       
                   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;
                   
              }
              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];
       
                   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;
                   
              }
              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];
       
                   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;
                   
              }
            }
             
      }
    }
  }
 
 uint8_t readByte()
  {
    while (true)
      {
if(delayMax <= millis())
        {
            break;
        }
        if (Serial.available() > 0)
        {
          return Serial.read();
        }
      }
    return 0; 
  }
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you have connected to pin 7 (you call the line RESET)? Is pin 7 connected to the RESET pin of the Arduino?

Which version of the IDE do you use?
Logged

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

I have connected on pin 7 the reset pin of arduino. I have the arduino1.0 with the data in .ino
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Upgrade to version 1.0.1 of the IDE. Version 1.0 had some problems with the Ethernet code that should be fixed in the new version. Compile your project with the new IDE and tell us if your freezes occur again. I guess you won't need your reset connection.

If you still have problems with freezing sketches, take a look at the watchdog features of the ATmega328:

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have the arduino1.0 with the data in .ino
Which, depending on your operating system, may contain a nasty bug that SurferTim documented and submitted a fix for. The fix IS part of the newer 1.0.1 version. I'd suggest that you upgrade.
Logged

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

Ok thanks you I'm upgrading the IDE. I hope that it comes from this version

As regards the watch dog, it could find in the loop or after the client.print?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As regards the watch dog, it could find in the loop or after the client.print?

I don't understand that sentence. Could you describe what you mean?
Logged

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

Sorry for my English, where we can put the watchdog on my code? after client.print?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anywhere in loop() where it's called often enough to reset the watchdog timer. At the start of the routine would be a possible place.
Logged

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

I find a solution on the watchdog :

Code:
void (*resetFunc)(void) = 0; //declare reset function at adress 0
...
resetFunc();
...

What do you think of this?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is not a reset, your just jumping to the bootloader code. For the ATmega328 this is similar to have got reset but all the other components don't get noticed and won't reset.
Logged

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

OK Ok it is not a watchdog, I just have to use the library <avr/wdt.h> and the command wdt_enable(WDTO_2S) for example. I hope that I would not use this command.
Logged

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

Upgrading IDE of arduino is not sufficient, my system stopped...I don't understand...
I try to put the watchdog in my code in order to see if it solves my problem...
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried connecting a PC and putting out debugging information to see where in your code it stops?

Installing the watchdog is fighting the symptoms but not solving the problem.
Logged

Pages: [1] 2   Go Up
Jump to: