ThingSpeak and Udoo NEO Full

Discussion in 'UDOO NEO' started by Andriy, Jun 29, 2016.

  1. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    Someone have experience Udoo NEO Full with ThingSpeak or Ubidots?
     
    Last edited: Jun 29, 2016
  2. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    Can i received and send of date to cloud from Barometric, Temp sensor and sensor (Seeedstudio) which to connect through Grove Shield?
     
  3. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    I received a reply from http://community.ubidots.com/
    Code:
    import time
    import sys
    import commands
    import subprocess
    from ubidots import ApiClient
    
    try:
    
        api = ApiClient(token="4d195c0044fcc3b9f6dab9d653af3")
    
    except:
    
        print("Couldn't connect to the API, check your Internet connection")
        sys.exit(0)
    
    while(1):
        data = commands.getstatusoutput('cat /sys/class/misc/FreescaleGyroscope/data')
        output = data[1].split(',')
        api.save_collection([{'variable':'5657616d762542269dfb3833','value':output[0]},{'variable':'56576179762542269dfb3849','value':output[1]},{'variable':'5657618476254227de42b754','value':output[2]}])
    
    How connect other sensor?
     
    Andrea Rovai likes this.
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Did you succeed in reading values from the Temperature sensor and the AirQuality sensor from the Arduino Serial monitor on the Udoo?
    Once you get that running you can have a python program read those values from serial and send them to the cloud.
    Other sensors that are connected directly to the Linux side can be read through Python or Java and the send to the cloud.
     
    Andrea Rovai likes this.
  5. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    The code sends data, but first wrote echo: I / O error:

    Code:
    #Sensor examples for everything builtin the board such as
    #Magnometer -> Magnetic pull on device
    #Gyroscope - > xyz tilt degree on the device
    #Accelerometer -> xyz directional force measurment
    # A library (example) to get the current values for the outboard sensors such as
    # Temperature sensor
    # Barometer
    
    from neo import Accel # import accelerometer
    from neo import Magno # import magnometer
    from neo import Gyro # import gyroscope
    from neo import Temp #import libraries
    from neo import Barometer
    
    from time import sleep # to add delays
    
    gyro = Gyro() # new objects p.s. this will auto initialize the device onboard
    accel = Accel()
    magno = Magno()
    temp = Temp() # init objects p.s. I auto initialize/reset the modules on these calls
    baro = Barometer()
    
    
    accel.calibrate()
    gyro.calibrate() # Reset current values to 0
    magno.calibrate()
    
    gyroVals = gyro.get() # Returns a full xyz list [x,y,z] realtime (integers/degrees)
    magnoVals = magno.get() # Above
    accelVals = accel.get() # Same as gyro return xyz of current displacment force
    tempVal = temp.getTemp("f") # replace f with c to get celcius
    pressureVal = baro.getPressure() # gets the pressure in kPA
    tempFromBaro = baro.getTemp("c") # slower than temp sensor but still works same as temp sensor replace c with f for different modes
    
    # Ubidots send
    import time
    import sys
    import commands
    import subprocess
    from ubidots import ApiClient
    
    try:
    
        api = ApiClient(token="my111111111111111111")
    
    except:
    
        print("Couldn't connect to the API, check your Internet connection")
        sys.exit(0)
    
    while(1):
        # Gyroscope - gyroVals
        api.save_collection([{'variable':'57764c607625426dabe59553','value':gyroVals[0]}, {'variable':'5777ab807625426b4b374590','value':gyroVals[1]},{'variable':'5777ad1a76254278d965ab79','value':gyroVals[2]}])
        #Magnometer - magnoVals
        api.save_collection([{'variable':'57791489762542273026d016','value':magnoVals[0]}, {'variable':'577914957625422752d8e2ee','value':magnoVals[1]},{'variable':'5779149e76254227fe248510','value':magnoVals[2]}])
        #Accelerometer - accelVals
        api.save_collection([{'variable':'5779209e762542373fde5702','value':accelVals[0]}, {'variable':'577920a776254237c318b71a','value':accelVals[1]},{'variable':'577920ad76254237e23ea12b','value':accelVals[2]}])
    #Temperature sensor - tempVal
        api.save_collection([{'variable':'5777bbe67625427a308c0c91','value':tempVal}])
    #Barometer - pressureVal
        api.save_collection([{'variable':'5779289a76254218a67eacaf','value':pressureVal}])
    #TempFromBaro
        api.save_collection([{'variable':'5777bbee7625427a763c7332','value':tempFromBaro}])
    
     
    Last edited: Jul 3, 2016
  6. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
  7. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    With "Ubidots" understood . Who has experience with the library "<ThingSpeak.h>" under UDOO NEO?
     
  8. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    It will not work as the Neo is not an Arduino with a wifi shield (prerequisite).
    The Neo is a raspberry pi-ish Linux computer with an Arduino on 1 board. Instead of the USB to talk between the Arduino and linux the Neo uses a special serial device called /dev/ttyMCC in Linux, and called "Serial" in Arduino.

    To put sensor data in thingspeak you use the Arduino to read the data, send it through Serial.println to Linux. On the Linux side use a python program to read the sensor data from Arduino (use /dev/ttyMCC) and send it to thingspeak.

    For examples how to send sensor data from Arduino to Linux see documentation Serial Library. http://www.udoo.org/docs-neo/Serial_Libraries/index.html

    For examples how to send data from Linux to thingspeak use Google (search for "raspberry pi thingspeak").
     
    Last edited: Jul 20, 2016
    Andrea Rovai likes this.
  9. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    I found python script on github:

    Code:
    import httplib, urllib
    from time import localtime, strftime
    # download from http://code.google.com/p/psutil/
    import psutil
    import time
    
    def doit():
        cpu_pc = psutil.cpu_percent()
        mem_avail_mb = psutil.avail_phymem()/1000000   
        params = urllib.urlencode({'field1': cpu_pc, 'field2': mem_avail_mb,'key':'YOURKEYHERE'})
        headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
        conn = httplib.HTTPConnection("api.thingspeak.com:80")
       
        try:
            conn.request("POST", "/update", params, headers)
            response = conn.getresponse()
            print cpu_pc
            print mem_avail_mb
            print strftime("%a, %d %b %Y %H:%M:%S", localtime())
            print response.status, response.reason
            data = response.read()
            conn.close()
        except:
            print "connection failed"   
    
    #sleep for 16 seconds (api limit of 15 secs)
    if __name__ == "__main__":
        while True:
            doit()
            time.sleep(16) 
    https://gist.github.com/AndriyHz/e7541e48e49d41339be4224fd3987e6f
     
    waltervl likes this.
  10. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    As said the linux part is raspberry pi-ish. So do not expect to pi specific python libraries to work. You have to use Neo specific libraries or do it without libraries.
     
    Andrea Rovai likes this.
  11. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Last edited: Dec 6, 2016
    Andriy likes this.
  12. Andriy

    Andriy Member

    Joined:
    Nov 10, 2015
    Messages:
    30
    Likes Received:
    2
    Thank! I will be try.
    How modification code for send data from Bricks or internal NEO sensor?
     
  13. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Please check and combine the different Neo Arduino examples for Neo Sensors and Bricks in the Arduino IDE on the Neo and make it one sketch that reads all your sensors.
    Motion Sensors: http://www.udoo.org/docs-neo/Arduino_M4_Processor/Controlling_9-axis_motion_sensors.html
    The Bricks are accessible through I2C-2 and you can use the Arduino examples in the Arduino IDE on the Neo.

    Please take it step for step. Try 1 example and slowly add the next one.
    Do not try to upload to Thingspeak straight away but first check if the Serial Monitor output of the Arduino IDE is correct.
    In my example the Serial output waits until something appears on the serial line from A9 so you first have to send a character to the Arduino before the Serial monitor will print the values to your serial monitor. So don't panic if at first nothing shows up.
     

Share This Page