Send output info over SMS(UNO and SIM800L)

I'm working with a project I found that processes and displays data in a terminal.
Instead of displaying the output I need it to be sent as SMS over a SIM800L module.

Below is the section of code that references the information I want to be sent over SMS. It is meant to be displayed in a terminal program made by the developer.

debug("**Value#1**: ");     *//This is information I need*
		while(buff[--i] != FieldSeparator) {
			USART_tx(buff[i]);
		}
		debug("\r");
	
		debug("**Value#2:** ");     *//This is information I need*
		while(buff[--i] != FieldSeparator) {
			USART_tx(buff[i]);
		}
		debug("\r");

		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = buff[--i]; cbuff[4] = '\0';
		debug("**Value#3:** ");     *//This is information I need*
		debug(cbuff); debug("\r");
		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = '\0';
		debug("**Value#4:** ");     *//This is information I need*
		debug(cbuff); debug("\r");
		debug("**Value#5:** ");     *//This is information I need*
		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = buff[--i]; cbuff[4] = '\0';
		debug(cbuff); debug("\r");
		debug("**Value#6:** ");     *//This is information I need*
		while(buff[i] != FieldSeparator && buff[i] != StopSentinel) {
			USART_tx(buff[i]);
			--i;
		}
		debug("\r");
	}
	else {	// Process other formats here


	}
}

In the terminal program, the processed data is shown after the colon.
"Value#1 : xxxxx"
I need all data values #1- #6. Preferably in the same text message but separate will not be a problem.
Where should I start? This is one of my first Arduino projects so I'm still clueless.

Don't post snippets (Snippets R Us!)

by the look of it your buffer buff[] holds the information you need in reverse order

  • value 1 is whatever is in the buffer at the current i position until FieldSeparator is reached
  • value 2 is whatever is in the buffer after you skipped the FieldSeparator until the next FieldSeparator
  • value 3 is the next 4 elements of the buffer
  • value 4 is the next 3 elements of the buffer
  • value 5 is the next 4 elements of the buffer
  • value 6 is whatever in the buffer after that until you reach the FieldSeparator or the StopSentinel whichever comes first

Here is the rest of the code

#include <avr/interrupt.h>
#include "common.h"
#include "uart.h"
#include <string.h>
#include <stdlib.h>

#define STROBE		PIND2	
#define PRESENT 	PIND3
#define	DATA1		PIND4


#define StartSentinel	'%'
#define StopSentinel	'?'
#define FieldSeparator	'^'
// Track two are different
#define T2StartSentinel	';'
#define T2StopSentinel	'?'
#define T2FieldSeparator '='

// Our buffer and mask index
#define MAX_BUFF_SZ1	256	// power of 2
#define	MAX_BUFF_SZ2	64


volatile char				buff[MAX_BUFF_SZ1];
volatile int8_t				bit;
volatile uint8_t			idx;
volatile uint8_t			bDataPresent;

static void InitInterrupt(void);
static void ReadData(void);
static void ProcessData(void);
static void InitData(void);
static void debug(char const *);
static void WriteString(const char *);

int main()
{
	char cbuff[5];	// general translation buffer

	// setup STATUS_LED for output
	BSET(DDRB,DDB5);
	BSET(PORTB,STROBE);	// pullup
	BSET(PORTB,DATA1);		
	BSET(PORTB,PRESENT);	// present goes high 150ms after last tx

	USART_init(BAUD_57600, INT_NONE);
	InitData();
	InitInterrupt();

	debug("System initialized!\r");
	debug("Checking for data after ");
	debug(itoa((CHECK_TIME/1000),cbuff,10));
	debug("ms\r");

	for (;;)
	{
		if( TCNT1 >= CHECK_TIME)
		{	
			StopTimer();
			ClearTimer();

			ProcessData();
			ReadData();			

			idx = 0;
			bit = 6;
			bDataPresent = 0;
			memset(&buff,0,MAX_BUFF_SZ1);

		}	
	}
}

void
ProcessData(void)
{
	uint8_t i;
	for (i = 0; i < (idx-1); i++)
	{
		// Contains a parity bit
		// TODO check parity
		BCLR(buff[i],6);

		// and is 0x20 from ASCII
		buff[i] += 0x20;
	}

	char cbuff[3];
	WriteString("\r\rM digits: ");
	WriteString(itoa(idx,cbuff,10));
	USART_tx('\r');

}

void
ReadData(void)
{
	uint8_t i = (idx - 1);
	char cbuff[5];

	while (buff[i] != StartSentinel && i != 0) --i;
	if (i == 0) {
		debug("Invalid format. Try again.\r");
		return;
	}
	debug("Card Format: ");
	USART_tx(buff[--i]);
	debug("\r");
	if (buff[i] == 'B') {

		debug("Value#1: ");
		while(buff[--i] != FieldSeparator) {
			USART_tx(buff[i]);
		}
		debug("\r");
		
		debug("Value#2: ");
		while(buff[--i] != FieldSeparator) {
			USART_tx(buff[i]);
		}
		debug("\r");

		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = buff[--i]; cbuff[4] = '\0';
		debug("Value#3: ");
		debug(cbuff); debug("\r");
		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = '\0';
		debug("Value#4: ");
		debug(cbuff); debug("\r");
		debug("Value#5: ");
		cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = buff[--i]; cbuff[4] = '\0';
		debug(cbuff); debug("\r");
		debug("Value#6: ");
		while(buff[i] != FieldSeparator && buff[i] != StopSentinel) {
			USART_tx(buff[i]);
			--i;
		}
		debug("\r");
	}
	else {	// Process other formats here


	}
}

void
InitInterrupt(void)
{
	// Setup interrupt
	BSET(EIMSK,INT0);	// external interrupt mask
	BSET(EICRA,ISC01);	// falling edge
	BCLR(EICRA,ISC00);	// falling edge

	BSET(SREG,7);		// I-bit in SREG
}

#include <avr/interrupt.h>
ISR(INT0_vect)
{
	StopTimer();
	ClearTimer();

	if ( !BCHK(PIND,DATA1) )	// inverse low = 1
	{
		BSET(GPIOR0,bit);
		--bit;
		bDataPresent = 1;
	} else if (bDataPresent) {
		BCLR(GPIOR0,bit);
		--bit;
	}

	if (bit < 0) {
		buff[idx] = (char)GPIOR0;
		++idx;
		bit = 6;
	}
		
	StartTimer();
}

static void
InitData(void)
{
	memset(&buff,0,MAX_BUFF_SZ1);
	bit = 6; idx = 0;
	bDataPresent = 0;
	GPIOR0 = 0x00;
}


static void
debug(char const * msg)
{
	while(*msg != 0x00)
		USART_tx(*(msg++));
}

void WriteString(const char * msg)
{
	while (*msg != 0x00)
		USART_tx(*(msg++));
}


Okay I understand it a bit better now. So, I'll just send everything in the buffer as an SMS and manually separate it.
How could I reference this specific buffer in the serial monitor?

well the data is stored in reverse order, so it requires to be read from the end to be "readable" apparently

They all seem to be cStrings, so just create 6 buffers large enough to accommodate the text and copy the relevant bits into each buffer and add the trailing null
that's what they do with this for example

char cbuff[5];
...
cbuff[0] = buff[--i]; cbuff[1] = buff[--i]; cbuff[2] = buff[--i]; cbuff[3] = buff[--i]; cbuff[4] = '\0';

they have a 5 byte long cbuff buffer, fill it in with the content of buff (in reverse direction) and then add the trailing null in the last byte.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.