Skip to main content

codless user replay() question

2 years ago

codless user replay() question

Posted bygert1860 points 11 replies
0 upvotes

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 */
do {

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

2 years ago

MHv_Dialog

Hi Gert,

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

具体地说,我需要理解如果你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

2 years ago

gert186 0 points

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 1 time
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

2 years ago

MHv_Dialog

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

2 years ago

KevinL 5 points

Hi Gert,

Please try to close the sleep mode before the testing.

Best Regards

2 years ago

gert186 0 points

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

2 years ago

KevinL 5 points

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;

2 years ago

gert186 0 points

no Change! sorry

2 years ago

gert186 0 points

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?

2 years ago

PM_Dialog

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

2 years ago

gert186 0 points

No Sleep Mode is switched off.

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

accepted answer!

2 years ago

PM_Dialog

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