Show Posts
Pages: 1 [2] 3 4 ... 126
16  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 14, 2014, 08:01:30 pm
C++ compile:

Code:
nano hello.cpp

Code:
// 'Hello World!' program
#include <iostream>
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

Code:
g++  hello.cpp -o hello

Code:
root@Arduino:/mnt/sda1# ./hello
./hello: can't load library 'libstdc++.so.6'

if I recompile it with static link

Code:
g++  hello.cpp -o hello  -static

Every thing is working, but obviously that is not I want.

After google ,

Code:
opkg update
opkg install libstdcpp


Code:
g++  hello.cpp -o hello

Code:
root@Arduino:/mnt/sda1# ./hello
Hello World!
17  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 14, 2014, 12:17:53 am
Compile and install Lua Module(C API)

Install lua_devel:

Code:
cd /usr/local/include
wget -O lua_devel.tar.gz https://www.dropbox.com/s/66zxd9gvdf7lvib/lua_devel.tar.gz?dl=0 --no-check-certificate
tar -xzf lua_devel.tar.gz
rm lua_devel.tar.gz

Download and compile lua-cjson:

Code:
cd /mnt/sda1/
wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
tar -xzf lua-cjson-2.1.0.tar.gz
cd /mnt/sda1/lua-cjson-2.1.0

Code:
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o lua_cjson.o lua_cjson.c
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o strbuf.o strbuf.c
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o fpconv.o fpconv.c
gcc  -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o

Install lua-cjson:

Code:
cp cjson.so /usr/lib/lua/

Testing lua-cjson:

Code:
cd /mnt/sda1/
nano arduino.lua

Code:
#!/usr/bin/lua
-------simple data-------
local tab ={}
tab["arduino"] = "arduino.cc"
--encode json -------
local cjson = require "cjson"
local jsonData = cjson.encode(tab)
 
print(jsonData)
-- print result:  {"arduino":"arduino.cc"}
 
--decode json -------
local data = cjson.decode(jsonData)
 
print(data.arduino)
-- print result:  arduino.cc

Code:
root@Arduino:/mnt/sda1# chmod 755 arduino.lua
root@Arduino:/mnt/sda1# ./arduino.lua
{"arduino":"arduino.cc"}
arduino.cc

lua-cjson (C-API)  V.S.  pure lua  json module performance boost 1000% to 2000%!



18  Using Arduino / Project Guidance / Re: Send photos via GSM-GPRS shield to Dropbox on: September 13, 2014, 07:41:21 pm
Use fswebcam to capture picture from USB camera.

http://forum.arduino.cc/index.php?topic=253571.msg1795704#msg1795704

Using Dropbox as yun backup space

http://forum.arduino.cc/index.php?topic=266283.msg1877607#msg1877607

Use 3G dongle to connect to internet. Yun, 3G dongle and yun_3g library

http://forum.arduino.cc/index.php?topic=236482.msg1877032#msg1877032

Put above into one script command (only 4~5 lines code).

Use crontab  to schedule run time.

crontab -e
0 * * * * /path_to_executable command

m      h       dom             mon     dow          command
Minute Hour    Day of Month    Month   Day of week  <command>
And your 0 * * * * <command> then translates to "Execute command on every hour, every day, every month, and every weekday, if the minute is 0"
19  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 13, 2014, 11:05:10 am
How to read serial data in Yun with C

http://forum.arduino.cc/index.php?topic=265394.msg1880075#msg1880075
20  Products / Arduino Yún / Re: Arduino YUN custom openwrt C program communication with arduino on: September 13, 2014, 10:56:04 am
Code:
root@Arduino:/mnt/sda1# nano arduino.c

Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
 
/* Yun is on /dev/ttyATH0 */
char *portname = "/dev/ttyATH0";
char buf[256];
 
int main(int argc, char *argv[])
{
 int fd;
 
/* Open the file descriptor in non-blocking mode */
 fd = open(portname, O_RDWR | O_NOCTTY);
 
/* Set up the control structure */
 struct termios toptions;
 
 /* Get currently set options for the tty */
 tcgetattr(fd, &toptions);
 
/* Set custom options */
 
/* 9600 baud */
 cfsetispeed(&toptions, B9600);
 cfsetospeed(&toptions, B9600);
 /* 8 bits, no parity, no stop bits */
 toptions.c_cflag &= ~PARENB;
 toptions.c_cflag &= ~CSTOPB;
 toptions.c_cflag &= ~CSIZE;
 toptions.c_cflag |= CS8;
 /* no hardware flow control */
 toptions.c_cflag &= ~CRTSCTS;
 /* enable receiver, ignore status lines */
 toptions.c_cflag |= CREAD | CLOCAL;
 /* disable input/output flow control, disable restart chars */
 toptions.c_iflag &= ~(IXON | IXOFF | IXANY);
 /* disable canonical input, disable echo,
 disable visually erase chars,
 disable terminal-generated signals */
 toptions.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);
 /* disable output processing */
 toptions.c_oflag &= ~OPOST;
 
/* wait for 24 characters to come in before read returns */
 toptions.c_cc[VMIN] = 12;
 /* no minimum time to wait before read returns */
 toptions.c_cc[VTIME] = 0;
 
/* commit the options */
 tcsetattr(fd, TCSANOW, &toptions);
 
/* Wait for the Arduino to reset */
 usleep(1000*1000);
 /* Flush anything already in the serial buffer */
 tcflush(fd, TCIFLUSH);
 /* read up to 128 bytes from the fd */
 int n = read(fd, buf, 128);
 
/* print how many bytes read */
 printf("%i bytes got read...\n", n);
 /* print what's in the buffer */
 printf("Buffer contains...\n%s\n", buf);
 
return 0;
}

Code:
root@Arduino:/mnt/sda1# gcc -o arduino arduino.c
root@Arduino:/mnt/sda1# ./arduino
12 bytes got read...
Buffer contains...
Hello World

http://chrisheydrick.com/2012/06/12/how-to-read-serial-data-from-an-arduino-in-linux-with-c-part-1/
21  Products / Arduino Yún / Re: Arduino YUN custom openwrt C program communication with arduino on: September 13, 2014, 10:53:23 am
Install screen for testing:

Code:
opkg update
opkg install screen

screen /dev/ttyATH0 9600

Code:
Hello World
           Hello World
                      Hello World
                                 Hello World

To exit screen type “ctrl-a \” without the quotes.
22  Products / Arduino Yún / Re: Arduino YUN custom openwrt C program communication with arduino on: September 13, 2014, 10:51:40 am
Arduino code:

Code:
void setup()
 
{
 
Serial.begin(9600);
Serial1.begin(9600);
 
}
 
void loop()
 
{
 
Serial.print("Hello World\n");
Serial1.print("Hello World\n");
 
delay(1000);
 
}
23  Products / Arduino Yún / Re: Arduino YUN custom openwrt C program communication with arduino on: September 13, 2014, 10:49:24 am
1. Disable redirect UART to ash shell (Bridge is disabled!)

Code:
nano /etc/inittab
#ttyATH0::askfirst:/bin/ash --login

http://forum.arduino.cc/index.php?topic=191820.msg1679588#msg1679588


2. Make sure Yun run correct buad rate:

Upgrade firmware.

http://forum.arduino.cc/index.php?topic=191820.msg1786485#msg1786485

3. Fix kernel command line warning error message:

http://forum.arduino.cc/index.php?topic=265031.msg1870219#msg1870219

Code:
dmesg

[   79.510000] wlan0: RX AssocResp from d8:50:e6:d7:ea:1e (capab=0xc11 status=0 aid=1)
[   79.520000] wlan0: associated
[   79.520000] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

anything after boot .
24  Products / Arduino Yún / Re: From Linino small C++ Daemon talking to Microsoft SQL Server/Web Server on: September 13, 2014, 12:23:45 am
4. http://forum.arduino.cc/index.php?topic=266549.msg1879526#msg1879526
25  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 13, 2014, 12:15:47 am
Install driver, library, application for Yun.

The freetds-dev  is open source library for Sybase  and Microsoft SQL server.

Code:
wget ftp://ftp.freetds.org/pub/freetds/current/freetds-dev.0.92.812.tar.gz
tar -zxvf freetds-dev.0.92.812.tar.gz

Code:
cd  freetds-dev.0.92.812


Code:
./configure
make
make install

Here you need take very long coffee break at stage "make"!

Testing connect to MS SQL Server

Code:
tsql -H192.168.0.111 -p 1433  -U sa -P password
locale is "C"
locale charset is "ASCII"
using default charset "ISO-8859-1"
1> use AdventureWorks2008
2> go
1> SELECT * FROM Person.Address where AddressID=1
2> go
AddressID       AddressLine1    AddressLine2    City    StateProvinceID PostalCode      SpatialLocation rowguid ModifiedDate
1       1970 Napa Ct.   NULL    Bothell 79      98011   e6100000010cae8bfc28bce4474067a89189898a5ec0    9AADCB0D-36CF-483F-84D8-585C2D4EC6E9    Jan  4 1998 12:00:00:000AM
(1 row affected)

Now Yun is able to directly talk to Sybase  and Microsoft SQL server.




26  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 12, 2014, 11:56:11 pm
Help Compile/Installing Python Modules:

Two type Python Modules; The first type is the pure Python one will be easily install by

Code:
pip install #modulename

or even simply copy/download python files into proper location.

http://forum.arduino.cc/index.php?topic=266283.0


The second type is C-API which is needed compile, gcc will help.

Sample  Install crcmod:

Install python_devel

Code:
cd /usr/include/python2.7
wget -O  python_devel.tar.gz https://www.dropbox.com/s/z49hrigv3umaaj8/python_devel.tar.gz?dl=0 --no-check-certificate
tar -zxvf python_devel.tar.gz
rm python_devel.tar.gz

Download crcmod

Code:
cd /mnt/sda1
wget https://pypi.python.org/packages/source/c/crcmod/crcmod-1.7.tar.gz --no-check-certificate
tar -zxvf  crcmod-1.7.tar.gz
cd crcmod-1.7
python setup.py build

Code:
gcc -fno-strict-aliasing -Os -pipe \
-mips32r2 -mtune=mips32r2 -fno-caller-saves  \
-Wno-error=unused-but-set-variable -msoft-float -DNDEBUG -Os \
-fPIC -I/usr/include/python2.7 \
-c python2/src/_crcfunext.c -o build/temp.linux-mips-2.7/python2/src/_crcfunext.o

gcc -pthread -shared build/temp.linux-mips-2.7/python2/src/_crcfunext.o \
-L/usr/lib  -o build/lib.linux-mips-2.7/crcmod/_crcfunext.so


Code:
python setup.py install
27  Products / Arduino Yún / Re: Example of Native GCC for Yun on: September 12, 2014, 11:45:51 pm
Help compile C (sshpass) application:

http://forum.arduino.cc/index.php?topic=253943.msg1799995#msg1799995

Code:
opkg update
opkg install tar


wget http://pkgs.fedoraproject.org/repo/pkgs/sshpass/sshpass-1.05.tar.gz/c52d65fdee0712af6f77eb2b60974ac7/sshpass-1.05.tar.gz

tar -zxvf sshpass-1.05.tar.gz

cd sshpass-1.05

./configure
make
make install
28  Products / Arduino Yún / Example of Native GCC for Yun on: September 12, 2014, 11:36:03 pm
 Say Hello to MIPS Assembly Language at Yun

Code:
nano hello.s

Code:
# File: hello.s -- Say Hello to MIPS Assembly Language Programmer
# Author: falcon <wuzhangjin@gmail.com>, 2009/01/17
# Ref:
#    [*] http://www.tldp.org/HOWTO/Assembly-HOWTO/mips.html
#    [*] MIPS Assembly Language Programmer's Guide
#    [*] See MIPS Run Linux(second version)
# Compile:
#       $ gcc -o hello hello.s
#       or
#       $ as -o hello.o hello.s
#       $ ld -e main -o hello hello.o

    .text
    .globl main
main:

    .set noreorder
    .cpload $gp       # setup the pointer to global data
    .set reorder
                      # print sth. via sys_write
    li $a0, 1         # print to standard ouput
    la $a1, stradr    # set the string address
    lw $a2, strlen    # set the string length
    li $v0, 4004      # index of sys_write:
                      # __NR_write in /usr/include/asm/unistd.h
    syscall           # causes a system call trap.

                      # exit via sys_exit
    move $a0, $0      # exit status as 0
    li $v0, 4001      # index of sys_exit
                      # __NR_exit in /usr/include/asm/unistd.h
    syscall

    .rdata
stradr: .asciiz "hello, world!\n"
strlen: .word . - stradr  # current address - the string address
# end


Code:
root@Arduino:/mnt/sda1# gcc -o hello hello.s
root@Arduino:/mnt/sda1# ./hello
hello, world!
29  Products / Arduino Yún / Re: Local Time not sticking on YUN on: September 11, 2014, 04:10:20 pm
output of

Code:
date

and

Code:
ps |grep ntpd

Confirm yun has internet connection?

Code:
opkg update
30  Products / Arduino Yún / Re: start_stop_deamon - does not take deamon arguments - Please advise on: September 11, 2014, 04:07:20 pm
Use .pyo file for security purpose?  hide source code?
Pages: 1 [2] 3 4 ... 126