codless user replay() question

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
12 posts / 0 new
Last post
gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
codless user replay() question

hi,

I wrote a new AT Command with 1wire:

else if(user_compare_cmd("1wire",1,2))
{
TM_OneWire_t OW;
uint8_t port = ahtoi((char*)argument_array[0]);
uint8_t port_number = port / 10;
uint8_t pin_number = port % 10;
uint8_t DS_ROM[8];
char message[8];
float temp;

TM_OneWire_Init(&OW, (GPIO_PORT)port_number, (GPIO_PIN)pin_number);
TM_OneWire_Reset(&OW);

if (TM_OneWire_First(&OW)) {
//Conversasion
TM_DS18B20_StartAll(&OW);
systick_wait(750000); // wait 750ms

/* Search for next devices */
{做

TM_OneWire_GetFullROM(&OW, DS_ROM);
TM_DS18B20_Read(&OW, DS_ROM, &temp);
sprintf(message, "%x%x%x%x,%0.2f",DS_ROM[4], DS_ROM[5], DS_ROM[6], DS_ROM[7],temp); // DS_ROM[0], DS_ROM[1], DS_ROM[2], DS_ROM[3],
//arch_printf("ATr+PRINT=%s\r",message);
user_reply(message,true);
} while (TM_OneWire_Next(&OW));
}
}

works fine but it I would like to send the values in message to peer with user_replay(message,true)
void user_reply(char* reply_string, bool success)
{
if(!codeless_env.suppress_response)
{
if(success)
{
// Append 'OK' to response
if(strlen(reply_string)>0)
sprintf(reply_string,"%s\r\nOK",reply_string);
else
reply_string = "OK";
}
else
{
// Report 'ERROR'
sprintf(reply_string,"ERROR");
}

// Reply to BT Peer if the command originated there (only if connected)
if((codeless_env.command_route == CMD_FROM_PEER_RESP_PEER) && (ke_state_get(TASK_APP)==APP_CONNECTED))
{
send_to_peer(reply_string);
}
else if(codeless_env.command_route == CMD_FROM_LOCAL_RESP_LOCAL)
{
// Reply locally via serial port
arch_puts(“\ r \n");
arch_puts(reply_string);
arch_puts(“\ r \n");
arch_printf_process();
}
//codeless_env.command_route = CMD_ROUTE_UNDEFINED;
}
}

I only got the last string. If I have 10 sensors installed, ten times the last one.....

if i uncomment //codeless_env.command_route = CMD_ROUTE_UNDEFINED;
Then I only get the first one..

Can someone helps me please to understand the problem?

Best regards
Gert

Device:
MHv_Dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2013-12-06 15:10
Hi Gert,

Hi Gert,

Please try to describe what you are trying to accomplish. Your code listing alone leaves too many unknowns :o)

Specifically, I need to understand if you are actually trying to issue the command locally and want the reply to go back to the peer over the air. Also, I will need how much data you are trying to exchange. The reply string is limited to 160 characters.

/MHv

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
ok,

ok,

I would like to send from Master to Slave:

ATr+1wire=00 to start a reading from attached sensors on the slave (in this case 10) and send ID and value over the air back to the master!
The Master should print that values over the uart2 to the terminal.

COmmand send and execute works like a charm.
but the problem is that it sends something over the air to the master but the master only printing the first with
codeless_env.command_route = CMD_ROUTE_UNDEFINED 1time
and 10 times the last if you have
//codeless_env.command_route = CMD_ROUTE_UNDEFINED in void user_reply(char* reply_string, bool success).

And I do not understand why he is only printig out the last one on uart2.

Best regards
Gert

MHv_Dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2013-12-06 15:10
Hi Gert,

Hi Gert,

You are breaking the flow of commands because you repeatedly use the user_reply(). When a remote AT command is received, CodeLess sets the codeless_env.command_route to CMD_FROM_PEER_RESP_PEER which ensures that the reply goes back to the command originator. As soon as the reply has ben prepared for transmission the command_route is set to CMD_ROUTE_UNDEFINED to allow for the next command to be received (via Bluetooth or UART).

In your do-while loop, instead of using user_reply(), simply record your entire response back to the peer. Then outside the loop, use user_reply() to transmit the entire string as one reply. This allows for the CodeLess commandflow to remain intact. But remember, the reply can only be about 160 characters long.

/MHv

KevinL
Offline
Last seen:2 weeks 5 days ago
工作人员
加入:2017-11-06 13:52
Hi Gert,

Hi Gert,

Please try to close the sleep mode before the testing.

Best Regards

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
where should I close the

where should I close the Sleep mode? in user_replay function?

KevinL
Offline
Last seen:2 weeks 5 days ago
工作人员
加入:2017-11-06 13:52
in user_config.h

in user_config.h

Change the following variable to ARCH_SLEEP_OFF.
/******************************************
* Default sleep mode. Possible values are:
*
* - ARCH_SLEEP_OFF
* - ARCH_EXT_SLEEP_ON
* - ARCH_EXT_SLEEP_OTP_COPY_ON
*
******************************************
*/
static const sleep_state_t app_default_sleep_mode = ARCH_SLEEP_OFF.; // ARCH_EXT_SLEEP_ON;

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
no Change! sorry

no Change! sorry

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
For me there are also some

For me there are also some questions:

I cannot print more than 231 lines in a loop of 1000 at arch_printf().

It will stops after the 231 line.

I think it is a time issue of checking or an interrupt from Advertising? Is there some expert with codeless who can help me?

PM_Dialog
Offline
Last seen:5 days 10 hours ago
工作人员
加入:2018-02-08 11:03
Hi gert186,

Hi gert186,

Your description is little bit generic, please provide me more info about it. What do you mean with “lines”? Do you mean characters? Could you please let me know if you are using any of sleep modes configuration?

Thanks, PM_Dialog

gert186
Offline
Last seen:1 year 4 months ago
加入:2016-04-21 59
No Sleep Mode is switched off

No Sleep Mode is switched off.

I print out 231 times a character but it should be 1000 :-) The character is "1"

PM_Dialog
Offline
Last seen:5 days 10 hours ago
工作人员
加入:2018-02-08 11:03
Hi gert186,

Hi gert186,

Your description is still quite generic. There are many reasons that you are not able to do that. Could you please share the code snippet that you are using?

Thanks, PM_Dialog