Problems in SD operations

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problems in SD operations

Post by libelium-dev » Wed Oct 17, 2018 1:20 pm

Hi,

printHex function convert the value to ascii to be printed properly through the serial monitor. So you have to do something similar to that to save the value in the file.

Regards

arajakar
Posts: 13
Joined: Tue Sep 11, 2018 2:52 pm
Company: university oulu

Re: Problems in SD operations

Post by arajakar » Thu Oct 18, 2018 2:35 pm

Code: Select all

import pexpect
import time
import sys
import firebase_admin as fb
from firebase_admin import credentials,db
from datetime import datetime



cred = credentials.Certificate("/home/pi/ble-drone-firebase-adminsdk-rxato-2d3b8cae12.json")
fb.initialize_app(cred, {
    'databaseURL' : 'https://ble-drone.firebaseio.com'})
DEVICE = "00:07:80:05:90:CC " # address of your device
#"00:07:80:05:42:F3"
# Run gatttool interactively.
child = pexpect.spawn("gatttool -I")

root = db.reference()
# Connect to the device.
print("Connecting to:"),
print(DEVICE)
NOF_REMAINING_RETRY = 3


while True:
  try:
    child.sendline("connect {0}".format(DEVICE))
    child.expect("Connection successful", timeout=20)
  except pexpect.TIMEOUT:
    NOF_REMAINING_RETRY = NOF_REMAINING_RETRY-1
    if (NOF_REMAINING_RETRY>0):
      print "timeout, retry..."
      continue
    else:
      print "timeout, giving up."
      break
  else:
    print("Connected!")
    break
    # Presence Sensor

start = time.time()
print(start)
elapsed = 0

while (elapsed < 100):

    child.sendline("char-write-req 0x0020 abcd")
    time.sleep(1)
    child.sendline("char-write-req 0x0020 1234")
    timestamp = int(time.time())
    now = time.time()
    elapsed = now - start
    print(elapsed)
I was using following code to send two data values from raspberry pi to waspmote. Then I used following code to read those values from waspmote.

Code: Select all

#include <WaspBLE.h>
#include <WaspFrame.h>
uint16_t flag = 0;
// define file name: MUST be 8.3 SHORT FILE NAME
char filename[]="FILE5.TXT";

// define variable
uint8_t sd_answer;

void setup() 
{
 
  // 0. Turn BLE module ON
  BLE.ON(SOCKET0);

  // 1. Make Waspmote visible to other BLE modules
  BLE.setDiscoverableMode(BLE_GAP_GENERAL_DISCOVERABLE);

  // 2. Make Waspmote connectable to any other BLE device
  BLE.setConnectableMode(BLE_GAP_UNDIRECTED_CONNECTABLE);
  USB.println(F("Waiting for incoming connections..."));

   // open USB port
  USB.ON();
  USB.println(F("SD_3 example"));
  
    // Set SD ON
  SD.ON();
    
  // Delete file
  sd_answer = SD.del(filename);
  
  if( sd_answer == 1 )
  {
    USB.println(F("file deleted"));
  }
  else 
  {
    USB.println(F("file NOT deleted"));  
  }
    
  // Create file
  sd_answer = SD.create(filename);
  
  if( sd_answer == 1 )
  {
    USB.println(F("file created"));
  }
  else 
  {
    USB.println(F("file NOT created"));  
  }


}
void loop() 
{
  flag = BLE.readLocalAttribute(32);
  USB.print(F("Attribute Value: "));
  for (uint16_t i = 0; i < BLE.attributeValue[0]; i++)
  {
   
    USB.printHex(BLE.attributeValue[i+1]);
    SD.append(filename, (char*)(BLE.attributeValue[i+1]));
  }       
  
  USB.println();
  
  
}
My problem is after sometime waspmote serial monitor shows same value as follow. What can be the reason for this? Please reply me as soon as possible.
ttribute Value: ABCD
Attribute Value: 1234
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: 1234
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: 1234
Attribute Value: ABCD
Attribute Value: ABCD
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234
Attribute Value: 1234

arajakar
Posts: 13
Joined: Tue Sep 11, 2018 2:52 pm
Company: university oulu

Re: Problems in SD operations

Post by arajakar » Thu Oct 18, 2018 2:36 pm

I expect your speedy reply

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problems in SD operations

Post by libelium-dev » Mon Oct 22, 2018 9:04 am

Hi,

We think that if the serial monitor shows those values is due to the attribute changed. So please make sure that you don't change that.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest