Jump to content









Photo

Arduino UNO/Ethernet Shield and Alternating Data Stream Failure

uno arduino ethernet

  • Please log in to reply
1 reply to this topic

#1 Hydrus

Hydrus

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 05 August 2015 - 05:01 AM

Hello!  I have been working on a project utilizing the Arduino UNO R3 and Arduino Ethernet Shield.  My code grabs data from four sensors and then attempts to send them to four separate devices built into carriots.  My code is identical for each data stream sending to each device.  The data stream is sent after taking a reading.  If the sensors take a reading / send a data stream in the order 1, 2, 3, and 4, then data streams 1 and 3 never reach their devices in carriots.  Sensors 2 and 4 successfully send their data to carriots.  A sample of my code is below as well as the response in the serial monitor.  I'm uncertain why I cannot print a full HTTP response header after each reading is sent.  My guess would be somehow resetting the ethernet connection after each data stream?  Any advice is welcome!

 

- Mark

 

------CODE SAMPLE (assume setup and variable declaration is correct)------
void loop() {
    digitalWrite(enable_1, LOW);
    digitalWrite(enable_2, HIGH);
    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);
    delay(50);                            
    altSerial.print("R\r");                         /*Send the command from the computer to the sensor using the soft serial port */
    delay(800);
    if (altSerial.available() > 0) {                 /*If data has been transmitted from sensor
      sensor_bytes_received = altSerial.readBytesUntil(13, sensordata, 30); //we read the data sent from the sensor until we see a <CR>. We also count how many character have been received */
      sensordata[sensor_bytes_received] = 0;         /*we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer */
      Serial.print("T(W): ");
      Serial.println(sensordata);                    /*let’s transmit the data received from the sensor to the serial monitor */
      tw_data = sensordata;
      delay(10);
      String arrayt[1][2] = {{"T(W)",tw_data}};
      delay(10);
      Serial.println(sender.send(arrayt, 1, APIKEY, DEVICET));
      delay(30000);
    }
    
    digitalWrite(enable_1, LOW);
    digitalWrite(enable_2, HIGH);
    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);
    delay(50);                            
    altSerial.print("R\r");
    delay(800);
    if (altSerial.available() > 0) {                 
      sensor_bytes_received = altSerial.readBytesUntil(13, sensordata, 30); 
      sensordata[sensor_bytes_received] = 0;       
      Serial.print("pH: ");
      Serial.println(sensordata);  
      ph_data = sensordata;
      delay(10);
      String arrayp[1][2] = {{"pH", ph_data}};
      delay(10);
      Serial.println(sender.send(arrayp, 1, APIKEY, DEVICEP));
      delay(30000);
    }
 
 
-------SERIAL MONITOR-------
Starting
T(W): 62.83
connected
 
pH: 4.032
HTTP/1.1 200 OK
Date: Wed, 05 Aug 2015 04:53:14 GMT
Content-Type: applicat
EC: 2536
connected
 
 
DO: 6.01
HTTP/1.1 200 OK
Date: Wed, 05 Aug 2015 04:54:17 GMT
Content-Type: applicat
T(W): 62.94
connected
 
 
pH: 4.026
HTTP/1.1 200 OK
Date: Wed, 05 Aug 2015 04:55:19 GMT
Content-Type: applicat
 


#2 Hydrus

Hydrus

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 06 August 2015 - 02:38 AM

UPDATE:

 

I'm uncertain what causes the issue, but I found a simple solution.  After running the sender.send() function once, I inserted delay(5000), then ran the same function again.  If anyone has any means by which to overcome this problem, let me know.  For now, I have enough to succeed. 

 

- Mark







Also tagged with one or more of these keywords: uno, arduino, ethernet

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users