Arduino Uno + Yun Shield

Hey guys! Kind of new to the Arduino. I have worked on the problem now for over a week, searching, testing without solution.

My project:

  • Arduino Uno w Yun Shield Ethernet and a DH22 2302 Digital Temperature Humidity Sensor

Task:

  • At a set ms parameter the temp and humdity is read and sent as a string to a mysql database over the ethernet.

Goals so far:

  • Webserver up and running, accepts strings over the .php file (included)
  • When just connecting the sensor to the Arduino and using code just for that, sensor values are reported.
  • Yun shield is detected from the router, and i can enter the webadmin of it

Problems:

  • When i upload my sensor and string poster on JUST the Arduino Uno it correctly uploads. But when i have the Yun Shield attached (and the sensor) i get the sync error:

System wide configuration file is “C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf”

Using Port : COM9
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xd8
avrdude: stk500_recv(): programmer is not responding


Facts:

  • Arduino is detected by windows, at com9, i have set the baud rate to 115200 via the device manager.
  • Arduino is found in the Arduino 1.6.5 on its correct comport

Code:

#include <DHT.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

#define DHTPIN 2 // SENSOR PIN
#define DHTTYPE DHT11 // SENSOR TYPE - THE ADAFRUIT LIBRARY OFFERS SUPPORT FOR MORE MODELS
DHT dht(DHTPIN, DHTTYPE);

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000; // READING INTERVAL

int t = 0;  // TEMPERATURE VAR
int h = 0;  // HUMIDITY VAR
String data;

void setup() { 
  Serial.begin(115200);

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }

  dht.begin(); 
  delay(10000); // GIVE THE SENSOR SOME TIME TO START

  h = (int) dht.readHumidity(); 
  t = (int) dht.readTemperature(); 

  data = "";
}

void loop(){

  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    h = (int) dht.readHumidity();
    t = (int) dht.readTemperature();
  }

data = "temp1=";

data.concat(t);

data.concat("&hum1=");

data.concat(h);
  if (client.connect("www.na.com/fangst",80)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /add.php HTTP/1.1"); 
    client.println("Host: na.com/fangst"); // SERVER ADDRESS HERE TO
    client.println("Content-Type: application/x-www-form-urlencoded"); 
    client.print("Content-Length: "); 
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 

  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }

  delay(300000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}

Error result:

Pastebin - Upload results with the Arduino/ Genuino Uno selected in the Arduino program

Pastebin - Upload results withe Arduino Yun shield selected in the Arduino program - http://pastebin.com/Pe8hqMYz

PHP script:

<?php include("connect.php"); $link=Connection(); $temp1=$_POST["temp1"]; $hum1=$_POST["hum1"]; $query = "INSERT INTO `tempLog` (`temperature`, `humidity`) VALUES ('".$temp1."','".$hum1."')"; mysql_query($query,$link); mysql_close($link); header("Location: index.php"); ?>

TapeStream:

Code:

...

#include <Ethernet.h>

Wrong code base, for Yun/Yun shield please use bridge class.

http://www.ibuyopenwrt.com/index.php/2-uncategorised/205-php-mysql-for-process-class

sonnyyu: Mysql, Microsoft SQL, Sybase, Sqlite3, NoSQL-MongoDB, PostgreSQL, DB in Memory (memcached).

http://www.ibuyopenwrt.com/index.php/datalog-db

To do list: Oracle, IBM DB2

|500x281

Yun/Yun shield support a lot of DB directly, no php midware is needed.

sonnyyu: The list of programming language Yun/Yun Shield supports:

  • Erlang (a general-purpose concurrent, garbage-collected programming language and runtime system)
  • Java
  • JavaScript
  • Lua
  • PHP
  • Perl
  • Python
  • Ruby
  • 4th (an imperative stack-based computer programming language and programming environment)
  • eggdrop (Eggdrop is a popular IRC bot and the oldest still in active development)
  • sigscheme (SigScheme is a R5RS Scheme interpreter for embedded use.)
  • slsh (Interpreter for S-Lang scripts)
  • tcl (Tool Command Language)
  • vala (C-sharp like language for the GObje)
  • C
  • C++
  • MIPS Assembly Language
  • Shell Scripts
  • Fortran

TapeStream: ... Problems: - When i upload my sensor and string poster on JUST the Arduino Uno it correctly uploads. But when i have the Yun Shield attached (and the sensor) i get the sync error:

System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM9 Using Programmer : arduino Overriding Baud Rate : 115200 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xd8 avrdude: stk500_recv(): programmer is not responding

...

Dragino Yun shield

Setup Dragino and Arduino IDE

That shield talks to the Arduino using the hardware serial pins/instance. That WILL interfere with loading a sketch on the Arduino while the shield is attached.

Nothing you can do about it except remove it when uploading.

This is NOT a programming issue.

PaulS: That shield talks to the Arduino using the hardware serial pins/instance. That WILL interfere with loading a sketch on the Arduino while the shield is attached.

Nothing you can do about it except remove it when uploading.

This is NOT a programming issue.

It is not true.

Yun shield + Uno/Leonardo/Mega

You could upload sketch directly via network port (WiFi, Ethernet)

|500x407

Yun shield + Leonardo only

You could upload sketch via USB as well

(image is "Yun shield + Leonardo", has 3 ports to select for uploading)

Thanks to all of you for posting! I really appriciate it!! Heres the new status:

So here is what i did, i downloaded the proper “driver”? So i could choose Arduino - Cards - Arduino Uno - Yun. Then I choose the now network found card under Ports: 4.4.4.4.150 (Yun). I then uploaded again and it asked me for the password, witch was the default draguino.

Here is the problem free upload now:

But it still does not send sensor values to the webserver, any tips on where to start searching for the error? A syslog from the card perhaps?

PS! Just followed this to upgrade it aswell, then i reuploaded the script: https://www.arduino.cc/en/Tutorial/YunSysupgrade

sonnyyu:
Wrong code base, for Yun/Yun shield please use bridge class.

http://www.ibuyopenwrt.com/index.php/2-uncategorised/205-php-mysql-for-process-class

Install software php and mysql driver at Yun/Yun shield.

opkg update
opkg install php5-mod-mysqli
opkg install php5-cli
nano /mnt/sda1/db.php
#!/usr/bin/php-cli
<?php
$temperature = $argv[1]; 
$DBServer = '192.168.0.20'; 
$DBUser   = 'root';
$DBPass   = 'password';
$DBName   = 'sensors';  
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
// check connection
if ($conn->connect_error) {
  trigger_error('Database connection failed: '  . $conn->connect_error, E_USER_ERROR);
}
$sql="INSERT INTO sensor_data (temperature) VALUES ($temperature)";
if($conn->query($sql) === false) {
  trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
} 
?>

"192.168.0.20" is your mysql server 's IP.

chmod 755 /mnt/sda1/db.php

Send test insert data without ATmega32u4:

/mnt/sda1/db.php  80

Make sure mysql has new insert data (80).

Upload ATmega32u4 's code:

#include <Process.h>
int temperature;
void setup() {
 Bridge.begin();  // Initialize Bridge
}
void loop() {
 int temperature = random(0, 100);
 Process p;              
 p.begin("/mnt/sda1/db.php");      
 p.addParameter(String(temperature)); 
 p.run();
 delay(5000); 
}

Thanks a lot again. Not sure how to do all this but will try over the next few days. I only wanted an arduino uno + yun shield, and for it to use some simple code over wan to send sensor strings.