Bluetooth Commands

In these notes "xx:xx:xx:xx:xx:xx" means the MAC address of the remote bluetooth device Reset Bluetooth Adaptor sudo hciconfig hci0 reset Restart Bluetooth Service sudo invoke-rc.d bluetooth restart List Bluetooth Adaptors hciconfig Scan for Bluetooth devices hcitool scan To then connect to one of the found devices  you can use this: sudo bluez-simple-agent hci0 xx:xx:xx:xx:xx:xx Make The […]

Read More

Set the RPi Time

Set the RPi Date and Time tm gps_date_time; char TimeString[128]; gps_date_time.tm_year = 20; gps_date_time.tm_mon = 1; gps_date_time.tm_mday = 1; gps_date_time.tm_hour = 1; gps_date_time.tm_min = 1; gps_date_time.tm_sec = 1; strftime(TimeString, 80, "%Y-%m-%dT%H:%M:%S", &gps_date_time); SetDataTimeString = "sudo date -s "; SetDataTimeString += TimeString; //Set the RPi time system((const char*)SetDataTimeString.c_str());  

Read More

DateTime calculations

Calculate the difference between two struct tm values Adjusting tm values (add/subtract secs, mins, days, etc) Adjusting the struct tm values won’t cause roll overs (e.g. if you -100 from .tm_second you will get a negative .tm_second value), you get left with the values adjusted but a potentially out of range value. mktime() is used to convert […]

Read More

Using Strings-Replace and Insert

Convert String to lowercase Be aware that ::tolower() can only do a per-single-byte-character substitution, which is ill-fitting for many scripts, especially if using a multi-byte-encoding like UTF-8. Replace Character In A String Note this only works for characters, there is no simple function to replace sections of a string :-( Replace String In A String […]

Read More

struct tm

A good way of storing and working with dates and time in C++.  A structure containing a calendar date and time broken down into its components. Creating a tm #include <ctime> tm my_date_time; my_date_time.tm_year = (2015 – 1900); //years since 1900 (we must be >= 1970 for time_t based calcs) my_date_time.tm_mon = 1; //months since January […]

Read More

Parameterized (Prepared) Statement Type Codes

  MYSQL_TYPE_TINY C Variable: signed char SQL Type: TINYINT (-128 to 127) MYSQL_TYPE_SHORT C Variable: short int (int16_t) SQL Type: SMALLINT (-32768 to 32767) MYSQL_TYPE_LONG C Variable: int (int32_t) SQL Type: INT (-2147483648 to 2147483647) MYSQL_TYPE_LONGLONG C Variable: long long int (int64_t) SQL Type: BIGINT (-9223372036854775808 to 9223372036854775807) MYSQL_TYPE_FLOAT C Variable: float SQL Type: FLOAT […]

Read More

Errors

Discovering Error That Occured Use this line after something doesn't work to discover what the problem was std::cout << "Database error: " << mysql_errno(mysql1) << " – " << mysql_error(mysql1) << std::endl;  

Read More

memset

Sets all of the bytes in a block of memory to a specified value memset(my_buffer, 0x00, sizeof(my_buffer)); //Set entire my_buffer to 0x00  

Read More

.stringstream General

stringstream is a handy class that operates on strings.  You can think it a file loaded into something resembling a string, or alternatively as a sort of string that you can write to and read from like a file. It’s not exactly either of those things, but its a simplified explanation. An example of a stringstream Using […]

Read More