PJSip make call issues in iPhone - voip

When I am trying to make a call using following code.
-(int)make_callWithURI:(char *) destURI{
/* Make call! : */
pj_str_t tmp;
pj_status_t status;
int regid = app_config.account_id;
int callNo = -1;
tmp = pj_str(destURI);
status = pjsua_call_make_call( regid, &tmp, 0, NULL, NULL, &callNo);
if (status != PJ_SUCCESS){
error_exit("Error making call", status);
return -1;
}
return callNo;
}
but getting signal SIGABRT at pjsua_call_make_call() line
Error log ::
16:18:04.376 pjsua_call.c !Making call with acc #0 to sip:mobile_number#sip_ip:port
16:18:04.376 pjsua_aud.c .Set sound device: capture=-1, playback=-2
16:18:04.376 pjsua_aud.c ..Opening sound device (speaker + mic) PCM#16000/1/20ms
16:18:04.376 coreaudio_dev. ...Using VoiceProcessingIO audio unit
16:18:04.378 tsx0x14e0cc8a8 !Timeout timer event
16:18:04.379 tsx0x14e0cc8a8 .State changed from Completed to Terminated, event=TIMER
16:18:04.379 tsx0x14e0cd0a8 Timeout timer event
16:18:04.379 tsx0x14e0cd0a8 .State changed from Completed to Terminated, event=TIMER
16:18:04.858 coreaudio_dev. !...core audio stream started
16:18:04.862 dlg0x14d8000a8 .UAC dialog created
16:18:04.862 dlg0x14d8000a8 ..Session count inc to 2 by mod-pjsua
List item
**16:18:04.862 pjsua_call.c .Error initializing media channel: Object is busy (PJ_EBUSY) [status=70011]
16:18:04.862 dlg0x14d8000a8 ..Session count dec to 1 by mod-pjsua
16:18:04.862 dlg0x14d8000a8 .Dialog destroyed
16:18:04.863 pjsua_media.c .Call 0: deinitializing media..
Assertion failed: (entry->cb != ((void*)0)), function schedule_w_grp_lock, file ../src/pj/timer.c, line 501.**
Please tell me why this issue is coming. I have initialise media with default configuration:
//initialize media config with default configuration
pjsua_media_config_default(&cfg->pjsua_media_cfg);

**> Please check this registration scenarios**
pj_status_t sip_startup(app_config_t *app_config)
{
pj_status_t status;
long val;
char tmp[80];
pjsua_transport_id transport_id = -1;
const char *srv;
const char *ip_addr;
NSArray * array;
NSString *dns;
SiphonApplication *app = (SiphonApplication *)[SiphonApplication sharedApplication];
/* Create pjsua first! */
status = pjsua_create();
if (status != PJ_SUCCESS)
return status;
/* Create pool for application */
app_config->pool = pjsua_pool_create("pjsua", 1000, 1000);
/* Initialize default config */
pjsua_config_default(&(app_config->cfg));
pj_ansi_snprintf(tmp, 80, "Siphon PjSip v%s/%s", pj_get_version(), PJ_OS_NAME);
pj_strdup2_with_null(app_config->pool, &(app_config->cfg.user_agent), tmp);
pjsua_logging_config_default(&(app_config->log_cfg));
val = [[NSUserDefaults standardUserDefaults] integerForKey:
#"logLevel"];
#ifdef RELEASE_VERSION
app_config->log_cfg.msg_logging = PJ_FALSE;
app_config->log_cfg.console_level = 0;
app_config->log_cfg.level = 0;
#else
app_config->log_cfg.msg_logging = (val!=0 ? PJ_TRUE : PJ_FALSE);
app_config->log_cfg.console_level = val;
app_config->log_cfg.level = val;
if (val != 0)
{
#if defined(CYDIA) && (CYDIA == 1)
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *path = [NSString stringWithFormat:#"%#/Siphon", [filePaths objectAtIndex:0]];
#else
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [filePaths objectAtIndex: 0];
#endif
//NSString *path = NSTemporaryDirectory();
path = [path stringByAppendingString: #"/log.txt"];
app_config->log_cfg.log_filename = pj_strdup3(app_config->pool,
[path UTF8String]);
}
#endif
pjsua_media_config_default(&(app_config->media_cfg));
// TODO select clock rate with enabled codec (8000 if nb codec only, or 16000 and more if wb codec)
//app_config->media_cfg.clock_rate = 8000;
//app_config->media_cfg.snd_clock_rate = 8000;
app_config->media_cfg.clock_rate = 16000;
app_config->media_cfg.snd_clock_rate = 16000;
//app_config->media_cfg.ec_options = 0;//0=default,1=speex, 2=suppressor
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"enableEC"])
app_config->media_cfg.ec_tail_len = 0;
// Enable/Disable VAD/silence detector
app_config->media_cfg.no_vad = [[NSUserDefaults standardUserDefaults]
boolForKey:#"disableVad"];
app_config->media_cfg.snd_auto_close_time = 0;
//app_config->media_cfg.quality = 2;
//app_config->media_cfg.channel_count = 2;
app_config->media_cfg.enable_ice = [[NSUserDefaults standardUserDefaults]
boolForKey:#"enableICE"];
pjsua_transport_config_default(&(app_config->udp_cfg));
val = [[NSUserDefaults standardUserDefaults] integerForKey: #"localPort"];
if (val < 0 || val > 65535)
{
PJ_LOG(1,(THIS_FILE,
"Error: local-port argument value (expecting 0-65535"));
[app displayParameterError:
#"Invalid value for Local Port (expecting 1-65535)."];
status = PJ_EINVAL;
goto error;
}
app_config->udp_cfg.port = val;
pjsua_transport_config_default(&(app_config->rtp_cfg));
app_config->rtp_cfg.port = [[NSUserDefaults standardUserDefaults]
integerForKey: #"rtpPort"];
if (app_config->rtp_cfg.port == 0)
{
enum { START_PORT=4000 };
unsigned range;
range = (65535-START_PORT-PJSUA_MAX_CALLS*4);
app_config->rtp_cfg.port = START_PORT +
((pj_rand() % range) & 0xFFFE);
}
if (app_config->rtp_cfg.port < 1 || app_config->rtp_cfg.port > 65535)
{
PJ_LOG(1,(THIS_FILE,
"Error: rtp-port argument value (expecting 1-65535)"));
[app displayParameterError:
#"Invalid value for RTP port (expecting 1-65535)."];
status = PJ_EINVAL;
goto error;
}
#if 1 // TEST pour le vpn
ip_addr = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"boundAddr"] UTF8String];
if (ip_addr && strlen(ip_addr))
{
pj_strdup2_with_null(app_config->pool,
&(app_config->udp_cfg.bound_addr),
ip_addr);
pj_strdup2_with_null(app_config->pool,
&(app_config->rtp_cfg.bound_addr),
ip_addr);
}
ip_addr = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"publicAddr"] UTF8String];
if (ip_addr && strlen(ip_addr))
{
pj_strdup2_with_null(app_config->pool,
&(app_config->udp_cfg.public_addr),
ip_addr);
pj_strdup2_with_null(app_config->pool,
&(app_config->rtp_cfg.public_addr),
ip_addr);
}
#endif
/* Initialize application callbacks */
app_config->cfg.cb.on_call_state = &on_call_state;
app_config->cfg.cb.on_call_media_state = &on_call_media_state;
app_config->cfg.cb.on_incoming_call = &on_incoming_call;
app_config->cfg.cb.on_reg_state = &on_reg_state;
#if defined(MWI) && MWI==1
app_config->cfg.cb.on_mwi_info = &on_mwi_info;
app_config->cfg.enable_unsolicited_mwi = PJ_TRUE;
#endif
srv = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"stunServer"] UTF8String];
if (srv && strlen(srv))
{
if (app_config->cfg.stun_srv_cnt==PJ_ARRAY_SIZE(app_config->cfg.stun_srv))
{
PJ_LOG(1,(THIS_FILE, "Error: too many STUN servers"));
return PJ_ETOOMANY;
}
pj_strdup2_with_null(app_config->pool,
&(app_config->cfg.stun_srv[app_config->cfg.stun_srv_cnt++]),
srv);
}
// app_config->cfg.outbound_proxy[0] = pj_str(outbound_proxy);
// app_config->cfg.outbound_proxy_cnt = 1;
dns = [[NSUserDefaults standardUserDefaults] stringForKey: #"dnsServer"];
array = [dns componentsSeparatedByString:#","];
NSEnumerator *enumerator = [array objectEnumerator];
NSString *anObject;
while (anObject = [enumerator nextObject])
{
NSMutableString *mutableStr = [anObject mutableCopy];
CFStringTrimWhitespace((CFMutableStringRef)mutableStr);
srv = [mutableStr UTF8String];
if (srv && strlen(srv))
{
if (app_config->cfg.nameserver_count==PJ_ARRAY_SIZE(app_config->cfg.nameserver))
{
PJ_LOG(1,(THIS_FILE, "Error: too many DNS servers"));
[mutableStr release];
break;
}
pj_strdup2_with_null(app_config->pool,
&(app_config->cfg.nameserver[app_config->cfg.nameserver_count++]),
srv);
}
[mutableStr release];
}
//[enumerator release];
//[array release];
/* Initialize pjsua */
status = pjsua_init(&app_config->cfg, &app_config->log_cfg,
&app_config->media_cfg);
if (status != PJ_SUCCESS)
goto error;
/* Initialize Ring and Ringback */
sip_ring_init(app_config);
/* Add UDP transport. */
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP,
&app_config->udp_cfg, &transport_id);
if (status != PJ_SUCCESS)
goto error;
/* Add RTP transports */
// status = pjsua_media_transports_create(&app_config->rtp_cfg);
// if (status != PJ_SUCCESS)
// goto error;
#if LOCAL_ACCOUNT
{
if (status == PJ_SUCCESS && transport_id != -1)
{
/* Add local account */
pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
}
}
#endif
/* */
sip_manage_codec();
/* Initialization is done, now start pjsua */
status = pjsua_start();
if (status != PJ_SUCCESS)
goto error;
return status;
error:
sip_cleanup(app_config);
return status;
}
/* */
pj_status_t sip_cleanup(app_config_t *app_config)
{
pj_status_t status;
/* Cleanup Ring and Ringback */
sip_ring_deinit(app_config);
if (app_config->pool)
{
pj_pool_release(app_config->pool);
app_config->pool = NULL;
}
/* Destroy pjsua */
status = pjsua_destroy();
pj_bzero(app_config, sizeof(app_config_t));
return status;
}
/* */
pj_status_t sip_connect(pj_pool_t *pool, pjsua_acc_id *acc_id)
{
pj_status_t status;
pjsua_acc_config acc_cfg;
const char *uname;
const char *authname;
const char *contactname;
const char *passwd;
const char *server;
SiphonApplication *app = (SiphonApplication *)[SiphonApplication sharedApplication];
// TODO Verify if wifi is connected, if not verify if user wants edge connection
uname = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"username"] UTF8String];
authname = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"authname"] UTF8String];
contactname = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"contact"] UTF8String];
passwd = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"password"] UTF8String];
server = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"server"] UTF8String];
pjsua_acc_config_default(&acc_cfg);
// ID
acc_cfg.id.ptr = (char*) pj_pool_alloc(/*app_config.*/pool, PJSIP_MAX_URL_SIZE);
if (contactname && strlen(contactname))
acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,
"\"%s\"<sip:%s#%s>", contactname, uname, server);
else
acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,
"sip:%s#%s", uname, server);
if ((status = pjsua_verify_sip_url(acc_cfg.id.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in local id argument",
acc_cfg.id));
[app displayParameterError: #"Invalid value for username or server."];
return status;
}
// Registrar
acc_cfg.reg_uri.ptr = (char*) pj_pool_alloc(/*app_config.*/pool,
PJSIP_MAX_URL_SIZE);
acc_cfg.reg_uri.slen = pj_ansi_snprintf(acc_cfg.reg_uri.ptr,
PJSIP_MAX_URL_SIZE, "sip:%s", server);
if ((status = pjsua_verify_sip_url(acc_cfg.reg_uri.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in registrar argument",
acc_cfg.reg_uri));
[app displayParameterError: #"Invalid value for server parameter."];
return status;
}
//acc_cfg.id = pj_str(id);
//acc_cfg.reg_uri = pj_str(registrar);
acc_cfg.cred_count = 1;
acc_cfg.cred_info[0].scheme = pj_str("Digest");
acc_cfg.cred_info[0].realm = pj_str("*");//pj_str(realm);
if (authname && strlen(authname))
acc_cfg.cred_info[0].username = pj_str((char *)authname);
else
acc_cfg.cred_info[0].username = pj_str((char *)uname);
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"enableMJ"])
acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_DIGEST;
else
acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
acc_cfg.cred_info[0].data = pj_str((char *)passwd);
acc_cfg.publish_enabled = PJ_TRUE;
#if defined(MWI) && MWI==1
acc_cfg.mwi_enabled = PJ_TRUE;
#endif
acc_cfg.allow_contact_rewrite = [[NSUserDefaults standardUserDefaults]
boolForKey:#"enableNat"];
// FIXME: gestion du message 423 dans pjsip
acc_cfg.reg_timeout = [[NSUserDefaults standardUserDefaults] integerForKey:
#"regTimeout"];
if (acc_cfg.reg_timeout < 1 || acc_cfg.reg_timeout > 3600)
{
PJ_LOG(1,(THIS_FILE,
"Error: invalid value for timeout (expecting 1-3600)"));
[app displayParameterError:
#"Invalid value for timeout (expecting 1-3600)."];
return PJ_EINVAL;
}
// Keep alive interval
acc_cfg.ka_interval = [[NSUserDefaults standardUserDefaults] integerForKey:
#"kaInterval"];
// proxies server
NSString *proxies = [[NSUserDefaults standardUserDefaults] stringForKey: #"proxyServer"];
NSArray *array = [proxies componentsSeparatedByString:#","];
NSEnumerator *enumerator = [array objectEnumerator];
NSString *anObject;
while (anObject = [enumerator nextObject])
{
NSMutableString *mutableStr = [anObject mutableCopy];
CFStringTrimWhitespace((CFMutableStringRef)mutableStr);
const char *proxy = [mutableStr UTF8String];
if (proxy && strlen(proxy))
{
if (acc_cfg.proxy_cnt==PJ_ARRAY_SIZE(acc_cfg.proxy))
{
PJ_LOG(1,(THIS_FILE, "Error: too many proxy servers"));
[mutableStr release];
break;
}
pj_str_t pj_proxy;
pj_proxy.slen = strlen(proxy) + 8;
pj_proxy.ptr = (char*) pj_pool_alloc(pool, pj_proxy.slen);
pj_proxy.slen = pj_ansi_snprintf(pj_proxy.ptr, pj_proxy.slen, "sip:%s;lr", proxy);
if ((status = pjsua_verify_sip_url(pj_proxy.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%*.s' in proxy argument (%d)",
pj_proxy.slen, pj_proxy.ptr, status));
[mutableStr release];
[app displayParameterError: #"Invalid value for proxy parameter."];
continue;
}
acc_cfg.proxy[acc_cfg.proxy_cnt++] = pj_proxy;
}
[mutableStr release];
}
#if LOCAL_ACCOUNT
*acc_id = aid;
#else
status = pjsua_acc_add(&acc_cfg, PJ_TRUE, acc_id);
if (status != PJ_SUCCESS)
{
pjsua_perror(THIS_FILE, "Error adding new account", status);
[app displayParameterError: #"Error adding new account."];
}
#endif
return status;
}
/* */
pj_status_t sip_disconnect(pjsua_acc_id *acc_id)
{
pj_status_t status = PJ_SUCCESS;
if (pjsua_acc_is_valid(*acc_id))
{
status = pjsua_acc_del(*acc_id);
if (status == PJ_SUCCESS)
*acc_id = PJSUA_INVALID_ID;
}
return status;
}
/* */
pj_status_t sip_dial_with_uri(pjsua_acc_id acc_id, const char *uri,
pjsua_call_id *call_id)
{
// FIXME: récupérer le domain à partir du compte (acc_id);
// TODO be careful app already mustn't be in communication!
// TODO if not SIP connected, use GSM ? NSURL with 'tel' protocol
pj_status_t status = PJ_SUCCESS;
pj_str_t pj_uri;
// pjsua_msg_data msg_data;
// pjsip_generic_string_hdr subject;
// pj_str_t hvalue, hname;
PJ_LOG(5,(THIS_FILE, "Calling URI \"%s\".", uri));
status = pjsua_verify_sip_url(uri);
if (status != PJ_SUCCESS)
{
PJ_LOG(1,(THIS_FILE, "Invalid URL \"%s\".", uri));
pjsua_perror(THIS_FILE, "Invalid URL", status);
return status;
}
pj_uri = pj_str((char *)uri);
//status = pjsua_set_null_snd_dev();
status = pjsua_snd_is_active();
// hname = pj_str("Subject");
// hvalue = pj_str("phone call");
//
// pjsua_msg_data_init(&msg_data);
// pjsip_generic_string_hdr_init2(&subject, &hname, &hvalue);
// pj_list_push_back(&msg_data.hdr_list, &subject);
//
// status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);
status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, NULL, call_id);
if (status != PJ_SUCCESS)
{
pjsua_perror(THIS_FILE, "Error making call", status);
}
return status;
}
pj_status_t sip_dial(pjsua_acc_id acc_id, const char *number,
pjsua_call_id *call_id)
{
// FIXME: récupérer le domain à partir du compte (acc_id);f
// TODO be careful app already mustn't be in communication!
// TODO if not SIP connected, use GSM ? NSURL with 'tel' protocol
char uri[256];
const char *sip_domain;
sip_domain = [[[NSUserDefaults standardUserDefaults] stringForKey:
#"server"] UTF8String];
pj_ansi_snprintf(uri, 256, "sip:%s#%s", number, sip_domain);
return sip_dial_with_uri(acc_id, uri, call_id);
}
/* */
pj_status_t sip_answer(pjsua_call_id *call_id)
{
pj_status_t status;
status = pjsua_set_null_snd_dev();
status = pjsua_call_answer(*call_id, 200, NULL, NULL);
if (status != PJ_SUCCESS)
{
*call_id = PJSUA_INVALID_ID;
}
return status;
}
/* */
pj_status_t sip_hangup(pjsua_call_id *call_id)
{
pj_status_t status = PJ_SUCCESS;
//pjsua_call_hangup_all();
/* TODO Hangup current calls */
if (*call_id != PJSUA_INVALID_ID)
status = pjsua_call_hangup(*call_id, 0, NULL, NULL);
*call_id = PJSUA_INVALID_ID;
return status;
}
#if SETTINGS
/* */
pj_status_t sip_add_account(NSDictionary *account, pjsua_acc_id *acc_id)
{
pj_status_t status;
pjsua_acc_config acc_cfg;
const char *uname;
const char *passwd;
const char *server;
const char *proxy;
SiphonApplication *app = (SiphonApplication *)[SiphonApplication sharedApplication];
app_config_t *app_config = [app pjsipConfig];
// TODO Verify if wifi is connected, if not verify if user wants edge connection
uname = [[account objectForKey: #"username"] UTF8String];
passwd = [[account objectForKey: #"password"] UTF8String];
server = [[account objectForKey: #"server"] UTF8String];
proxy = [[account objectForKey: #"proxyServer"] UTF8String];
pjsua_acc_config_default(&acc_cfg);
// ID
acc_cfg.id.ptr = (char*) pj_pool_alloc(app_config->pool, PJSIP_MAX_URL_SIZE);
acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,
"sip:%s#%s", uname, server);
// FIXME : verify in settings view
if ((status = pjsua_verify_sip_url(acc_cfg.id.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in local id argument",
acc_cfg.id));
[app displayParameterError: #"Invalid value for username or server."];
return status;
}
// Registrar
acc_cfg.reg_uri.ptr = (char*) pj_pool_alloc(app_config->pool,
PJSIP_MAX_URL_SIZE);
acc_cfg.reg_uri.slen = pj_ansi_snprintf(acc_cfg.reg_uri.ptr,
PJSIP_MAX_URL_SIZE, "sip:%s", server);
// FIXME : verify in settings view
if ((status = pjsua_verify_sip_url(acc_cfg.reg_uri.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in registrar argument",
acc_cfg.reg_uri));
[app displayParameterError: #"Invalid value for server parameter."];
return status;
}
//acc_cfg.id = pj_str(id);
//acc_cfg.reg_uri = pj_str(registrar);
acc_cfg.cred_count = 1;
acc_cfg.cred_info[0].scheme = pj_str("Digest");
acc_cfg.cred_info[0].realm = pj_str("*");//pj_str(realm);
acc_cfg.cred_info[0].username = pj_str((char *)uname);
acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
acc_cfg.cred_info[0].data = pj_str((char *)passwd);
acc_cfg.publish_enabled = PJ_TRUE;
acc_cfg.allow_contact_rewrite = [[account objectForKey:#"enableNat"] boolValue];
// FIXME: gestion du message 423 dans pjsip
acc_cfg.reg_timeout = [[account objectForKey: #"regTimeout"] intValue];
// FIXME : verify in settings view
if (acc_cfg.reg_timeout < 1 || acc_cfg.reg_timeout > 3600)
{
PJ_LOG(1,(THIS_FILE,
"Error: invalid value for timeout (expecting 1-3600)"));
[app displayParameterError:
#"Invalid value for timeout (expecting 1-3600)."];
return PJ_EINVAL;
}
pj_str_t pj_proxy = pj_str((char *)proxy);
if (pj_strlen(&pj_proxy) > 0)
{
acc_cfg.proxy[0].ptr = (char*) pj_pool_alloc(app_config->pool,
PJSIP_MAX_URL_SIZE);
acc_cfg.proxy[0].slen = pj_ansi_snprintf(acc_cfg.proxy[0].ptr,
PJSIP_MAX_URL_SIZE, "sip:%s;lr", proxy);
// FIXME verify in settings view
if ((status = pjsua_verify_sip_url(acc_cfg.proxy[0].ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in proxy argument",
acc_cfg.reg_uri));
[app displayParameterError: #"Invalid value for proxy parameter."];
return status;
}
acc_cfg.proxy_cnt = 1;
}
status = pjsua_acc_add(&acc_cfg, PJ_TRUE, acc_id);
if (status != PJ_SUCCESS)
{
pjsua_perror(THIS_FILE, "Error adding new account", status);
[app displayParameterError: #"Error adding new account."];
}
return status;
}
#endif

Related

RFID not reading any card

My RFID wont read any card. The Rfid card is on with red led at D1. I do not know what is the problem though. Below is my code. Please assist
The picture is connection between the rfid and esp8266
//*******************************libraries********************************
//RFID-----------------------------
#include <SPI.h>
#include <MFRC522.h>
//NodeMCU--------------------------
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
//************************************************************************
#define SS_PIN D2 //D2
#define RST_PIN D1 //D1
//************************************************************************
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
//************************************************************************
/* Set these to your desired credentials. */
const char *ssid = "***";
const char *password = "***";
const char* device_token = " 4876407e7cbc0c2b";
//************************************************************************
String URL = "http://192.168.0.110/rfidattendance/getdata.php"; //computer IP or the server domain
String getData, Link;
String OldCardID = "";
unsigned long previousMillis = 0;
//************************************************************************
void setup() {
delay(1000);
Serial.begin(115200);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
//---------------------------------------------
connectToWiFi();
}
//************************************************************************
void loop() {
//check if there's a connection to Wi-Fi or not
if(!WiFi.isConnected()){
connectToWiFi(); //Retry to connect to Wi-Fi
}
//---------------------------------------------
if (millis() - previousMillis >= 15000) {
previousMillis = millis();
OldCardID="";
}
delay(50);
//---------------------------------------------
//look for new card
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;//got to start of loop if there is no card present
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
}
String CardID ="";
for (byte i = 0; i < mfrc522.uid.size; i++) {
CardID += mfrc522.uid.uidByte[i];
}
//---------------------------------------------
if( CardID == OldCardID ){
return;
}
else{
OldCardID = CardID;
}
//---------------------------------------------
// Serial.println(CardID);
SendCardID(CardID);
delay(1000);
}
//************send the Card UID to the website*************
void SendCardID( String Card_uid ){
Serial.println("Sending the Card ID");
if(WiFi.isConnected()){
HTTPClient http; //Declare object of class HTTPClient
//GET Data
getData = "?card_uid=" + String(Card_uid) + "&device_token=" + String(device_token); // Add the Card ID to the GET array in order to send it
//GET methode
Link = URL + getData;
// http.begin(Link); //initiate HTTP request //Specify content-type header
int httpCode = http.GET(); //Send the request
String payload = http.getString(); //Get the response payload
// Serial.println(Link); //Print HTTP return code
Serial.println(httpCode); //Print HTTP return code
Serial.println(Card_uid); //Print Card ID
Serial.println(payload); //Print request response payload
if (httpCode == 200) {
if (payload.substring(0, 5) == "login") {
String user_name = payload.substring(5);
// Serial.println(user_name);
}
else if (payload.substring(0, 6) == "logout") {
String user_name = payload.substring(6);
// Serial.println(user_name);
}
else if (payload == "succesful") {
}
else if (payload == "available") {
}
delay(100);
http.end(); //Close connection
}
}
}
//********************connect to the WiFi******************
void connectToWiFi(){
WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect)
delay(1000);
WiFi.mode(WIFI_STA);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
delay(1000);
}
//=======================================================================
When I execute it, the rfid scanner is turn on but it does not read any card. I am using MFRC522, The wifi is connected successfully. I already pin the connection correctly

How to send Dictionary datatype( a{ias} ) through gdbus?

I was trying to send different datatypes over dbus using gdbus. I am stuck at sending the following datatype : a{ias}. Does anyone send me a snippet or any ways to approach this problem?
I have got a snippet here,just replace the busname,path,interface,methodname in the below code.
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
GVariantBuilder* builder;
error = NULL;
**//Acquire bus connection**
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
NULL,
&error);
g_assert_no_error (error);
error = NULL;
**//Create proxy of remote object**
proxy= g_dbus_proxy_new_sync(connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo */
"org.busname", /* Services */
"/org/buspath", /* Path */
"org.interface", /* Interface */
NULL, /* GCancellable */
error);
GVariant *result;
GVariant *value;
GError *error;
error = NULL;
int i;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
**//Sending dictionary datatype start**
for (i = 0; i < 2; i++)
{
GVariantBuilder* builderAs = g_variant_builder_new(G_VARIANT_TYPE("as"));
for (int j = 0; j < 2; j++) {
g_variant_builder_add(builderAs, "s", "SomeString");
}
g_variant_builder_add(&builder, "{ias}",i,builderAs);
}
**//Sending dictionary end**
GVariant *v1 = g_variant_builder_end(&builder);
result = g_dbus_proxy_call_sync(proxy,
"MethodName",
g_variant_new_tuple(&v1, 1),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

connecting MS Access through VC++

I am new to VC++, I am trying to write a program(after lots of googling) which connects to ms access, but its showing connection error. What am I missing or doing something wrong.
Error: [Microsoft][ODBC Driver Manager] Invalid String or Buffer Length.
Here is what I am tring
Clearn_dbView::Clearn_dbView()
: COleDBRecordView(Clearn_dbView::IDD)
{
setUpODBC();
}
Clearn_dbView::~Clearn_dbView()
{
if(hDbConn != SQL_NULL_HANDLE)
{
// Free Connection.
SQLFreeHandle(SQL_HANDLE_DBC,hDbConn);
}
if(hOdbcEnv != SQL_NULL_HANDLE)
{
SQLFreeHandle(SQL_HANDLE_ENV, hOdbcEnv);
}
}
void Clearn_dbView::setUpODBC()
{
SQLRETURN sr; //Return call for ODBC
//Allocate Environment.
sr = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&hOdbcEnv);
if( sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
AfxMessageBox(_T("Error in Allocating Environment."));
// Set the App's ODBC Version
sr = SQLSetEnvAttr(hOdbcEnv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
AfxMessageBox(_T("Error in Setting ODBC Version."));;
// Allocate Connection
sr = SQLAllocHandle(SQL_HANDLE_DBC, hOdbcEnv, &hDbConn);
//sr = SQLAllocConnect(hOdbcEnv, &hDbConn);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
AfxMessageBox(_T("Error in Allocating Connection."));;
// Set Connect Timeout
sr = SQLSetConnectAttr(hDbConn, SQL_ATTR_LOGIN_TIMEOUT, (void*)5, 0);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
AfxMessageBox(_T("Error in Setting Login Timeout."));
}
void Clearn_dbView::displayODBCError(SQLRETURN sr, char *inMessage)
{
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO) {
SQLWCHAR SqlState[6];
SQLINTEGER NativeError;
SQLWCHAR ErrMsg[SQL_MAX_MESSAGE_LENGTH];
int i = 1;
char message[1000];
strcpy (message, "");
if (inMessage) {
strcpy(message, inMessage);
strcat(message, " — ");
}
sprintf(message, "%sError in SQLConnect(): %d.",message, sr);
MessageBoxA(NULL,message,"Error",MB_OK);
while(SQLGetDiagRec(SQL_HANDLE_DBC, hDbConn, i,SqlState, &NativeError,ErrMsg, sizeof(ErrMsg), NULL)
!= SQL_NO_DATA) {
sprintf(message,"Diag: %d, SQLSTATE: %s NativeError: %d ErrMsg: %s",i++, SqlState, NativeError, ErrMsg);
MessageBoxA(NULL,message,"Error",MB_OK);
}
}
}
void Clearn_dbView::connectwithdb()
{
SQLRETURN sr;
SQLCHAR szDSN[] = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DSN=D:\\Avi\\P\\mydb.mdb.dsn";
SQLCHAR szUID[] = "";
SQLCHAR szAuthStr[] = "";
if(hDbConn == NULL) {
MessageBox(_T("hDbConn IS NULL"));
return;
}
sr = SQLConnectA(hDbConn, (UCHAR *)szDSN, SQL_NTS,
(UCHAR *)szUID, SQL_NTS,
(UCHAR *) szAuthStr, SQL_NTS);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
{
displayODBCError(sr, "Error in OnViewConnectwithsqlconnect");
}
else
{
MessageBox(_T("else executed"));
MessageBox(_T("Connected OK"));
}
}
void Clearn_dbView::OnBnClickedConnect()
{
connectwithdb();
}
It appears that the DSN being specified in the following line is not valid:
SQLCHAR szDSN[] = "D:\\Avi\\P\\mydb.mdb";
Based on the string "D:\\Avi\\P\\mydb.mdb", it looks like the database file and path are being specified instead of the DSN.
You will need to be sure to create an ODBC DSN using the ODBC Administrator. You will provide a string for the Data Source Name field of the configuration. That string is what you will need to specify in your code for SQLCHAR szDSN[] = "".
Here is a link that explains the error in more general details, however; if you follow what is mentioned above, that should resolve the error.

OpenSL SL_IID_RATEPITCH and SL_IID_VOLUME for PCM Buffer Queues on Android

I have created a multichannel audio system in OpenSL ES on the Android NDK utilizing PCM buffer queues. I cannot seem to get the OS to support SL_IID_RATEPITCH and SL_IID_VOLUME despite the Android docs saying that these two interfaces are supported. Below is my initialization code. Am I doing something wrong?
static SLresult InitChannel(int i)
{
SLresult lRes;
OpenSLChannel *channel = &sndc[i];
// Initialize stuff for playing PCM channels
// Set-up sound audio source.
SLDataLocator_AndroidSimpleBufferQueue lDataLocatorIn;
lDataLocatorIn.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
// At most one buffer in the queue.
lDataLocatorIn.numBuffers = 1;
SLDataFormat_PCM lDataFormat;
lDataFormat.formatType = SL_DATAFORMAT_PCM;
lDataFormat.numChannels = 1; // Mono sound.
lDataFormat.samplesPerSec = SL_SAMPLINGRATE_22_05; // BASE_FREQUENCY
lDataFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
lDataFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
lDataFormat.channelMask = SL_SPEAKER_FRONT_CENTER;
lDataFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
SLDataSource lDataSource;
lDataSource.pLocator = &lDataLocatorIn;
lDataSource.pFormat = &lDataFormat;
SLDataLocator_OutputMix lDataLocatorOut;
lDataLocatorOut.locatorType = SL_DATALOCATOR_OUTPUTMIX;
lDataLocatorOut.outputMix = mOutputMixObj;
SLDataSink lDataSink;
lDataSink.pLocator = &lDataLocatorOut;
lDataSink.pFormat = NULL;
// Create and realize the sound player.
// We are going to need its SL_IID_PLAY and also SL_IID_BUFFERQUEUE interface
// now available thanks to the data locator configured in the previous step.
const SLuint32 lSoundPlayerIIDCount = 4;
const SLInterfaceID lSoundPlayerIIDs[] = { SL_IID_PLAY, SL_IID_BUFFERQUEUE, SL_IID_VOLUME, SL_IID_RATEPITCH };
const SLboolean lSoundPlayerReqs[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE };
lRes = (*mEngine)->CreateAudioPlayer(mEngine, &channel->mPlayerObj, &lDataSource, &lDataSink, lSoundPlayerIIDCount, lSoundPlayerIIDs, lSoundPlayerReqs);
if (lRes != SL_RESULT_SUCCESS)
return lRes;
lRes = (*channel->mPlayerObj)->Realize(channel->mPlayerObj, SL_BOOLEAN_FALSE);
if (lRes != SL_RESULT_SUCCESS)
return lRes;
lRes = (*channel->mPlayerObj)->GetInterface(channel->mPlayerObj, SL_IID_PLAY, &channel->mPlayer);
if (lRes != SL_RESULT_SUCCESS)
return lRes;
lRes = (*channel->mPlayerObj)->GetInterface(channel->mPlayerObj, SL_IID_BUFFERQUEUE, &channel->mPlayerQueue);
if (lRes != SL_RESULT_SUCCESS)
return lRes;
// Get Volume Interface
lRes = (*channel->mPlayerObj)->GetInterface(channel->mPlayerObj, SL_IID_VOLUME, &channel->mVolume);
if (lRes != SL_RESULT_SUCCESS)
{
Err_Printf("Volume interface not supported.\n");
// return lRes;
}
lRes = (*channel->mPlayerObj)->GetInterface(channel->mPlayerObj, SL_IID_RATEPITCH, &channel->mRatePitch);
if (lRes != SL_RESULT_SUCCESS)
{
Err_Printf("RatePitch interface not supported.\n");
// return lRes;
}
lRes = (*channel->mPlayerQueue)->RegisterCallback(channel->mPlayerQueue, SoundFinished, channel);
// slCheckErrorWithStatus(lRes, "Problem registering player callback (Error %d).", lRes);
lRes = (*channel->mPlayer)->SetCallbackEventsMask(channel->mPlayer, SL_PLAYEVENT_HEADATEND);
// slCheckErrorWithStatus(lRes, "Problem registering player callback mask (Error %d).", lRes);
}
//
// SystemInit
//
// Initialization for
// the sound subsystem.
//
void SystemInit(void)
{
mEngineObj = NULL;
mEngine = NULL;
mOutputMixObj = NULL;
Err_Printf("Starting OpenSL ES...\n");
SLresult lRes;
const SLuint32 lEngineMixIIDCount = 1;
const SLInterfaceID lEngineMixIIDs[] = { SL_IID_ENGINE };
const SLboolean lEngineMixReqs[] = { SL_BOOLEAN_TRUE };
const SLuint32 lOutputMixIIDCount = 2;
const SLInterfaceID lOutputMixIIDs[] = { SL_IID_VOLUME, SL_IID_RATEPITCH };
const SLboolean lOutputMixReqs[] = { SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE };
lRes = slCreateEngine(&mEngineObj, 0, NULL, lEngineMixIIDCount, lEngineMixIIDs, lEngineMixReqs);
if (lRes != SL_RESULT_SUCCESS)
goto ERROR; // lolwut?
lRes = (*mEngineObj)->Realize(mEngineObj, SL_BOOLEAN_FALSE);
if (lRes != SL_RESULT_SUCCESS)
goto ERROR;
lRes = (*mEngineObj)->GetInterface(mEngineObj, SL_IID_ENGINE, &mEngine);
if (lRes != SL_RESULT_SUCCESS)
goto ERROR;
lRes = (*mEngine)->CreateOutputMix(mEngine, &mOutputMixObj, lOutputMixIIDCount, lOutputMixIIDs, lOutputMixReqs);
lRes = (*mOutputMixObj)->Realize(mOutputMixObj, SL_BOOLEAN_FALSE);
int i;
for (i = 0; i < NUMCHANNELS; i++)
{
lRes = InitChannel(i);
if (lRes != SL_RESULT_SUCCESS)
goto ERROR;
}
return;
ERROR:
Err_Printf("Error while starting OpenSL ES.");
SystemShutdown();
}
SL_IID_VOLUME is supported, however it only allows attenuation (max gain is 0). A good approximation of OpenAL's 0.0-1.0 is:
float attenuation = 1.0f / 1024.0f + gain * 1023.0f / 1024.0f;
float db = 3 * log10(attenuation) / log10(2);
SLmillibel setGain = (SLmillibel)(db * 1000);
SL_IID_RATEPITCH is not supported, but SL_IID_PLAYBACKRATE is. Unfortunately, it only allows setting the speed from 0.5 to 2.0 at this time.

CoSign API: SAPI User Management (add edit delete) example?

My app enables external signers to sign documents. —Signers who are not employees. My app will create a CoSign digital certificate for them. Then they'll sign the document, then the user should be deleted from the system. I want my app to programmatically create/delete the users.
Is there a C# example of for the SAPI User Management API?
Here's a C# example of how to get user info
namespace UMSample
{
class Program
{
private const string ADMIN_USER = "AdminUser";
private const string ADMIN_PASS = "AdminPass";
static public int AddUser(string uid)
{
SAPIUM sapium = new SAPIUMClass();
SAPICrypt sapicrypt = new SAPICrypt();
int rc;
if ((rc = sapicrypt.Init()) != 0) return 1;
if ((rc = sapium.Init()) != 0) return 1;
UMSESHandle hSes = null;
// Handle Acquire
if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
// Logon as Administrator
if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
{
sapium.HandleRelease(hSes);
return 1;
}
string UserCN = uid + " Test User";
string UserEmail = uid+"#demo.com";
string Pwd = "12345678";
if ((rc = sapium.UserAdd(
hSes,
uid,
UserCN,
UserEmail,
Pwd,
1)) != 0)
{
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 1;
}
/*----------------------------------*/
// An example of how to get user info
UserHandle uh;
string s1, s2, s3, s4;
int c1, c2, c3, mask = 0, updtime = 0;
SAPI_UM_ENUM_USER_CERT_STATUS_TYPE certsts;
SAPI_UM_ENUM_USER_LOGIN_STATUS loginstat;
SAPI_UM_ENUM_USER_TYPE kind = SAPI_UM_ENUM_USER_TYPE.SAPI_UM_USER_TYPE_NONE;
SAPI_UM_ENUM_USER_ENROLLMENT_STATUS enroll = SAPI_UM_ENUM_USER_ENROLLMENT_STATUS.SAPI_UM_NONE_USER_ENROLLMENT_STATUS;
SAPI_UM_ENUM_USER_ENROLLMENT_REASON enrReason;
SAPI_UM_ENUM_PENDING_REQUEST_STATUS_TYPE certrqsts;
rc = sapium.UserGetByLoginName(hSes, uid, out uh);
rc = sapium.UserInfoGetEx(hSes, uh, out s1, out s2, out s3, ref kind, ref mask, ref updtime, out s4,
out enroll, out enrReason, out loginstat, out c1, out c2, out c3, out certsts, out certrqsts);
/*----------------------------------*/
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 0;
}
static public int DelUser(string uid)
{
SAPIUM sapium = new SAPIUMClass();
int rc;
if ((rc = sapium.Init()) != 0) return 1;
UMSESHandle hSes = null;
if ((rc = sapium.HandleAcquire(out hSes)) != 0) return 1;
if ((rc = sapium.Logon(hSes, ADMIN_USER, "", ADMIN_PASS)) != 0)
{
sapium.HandleRelease(hSes);
return 1;
}
if ((rc = sapium.UserDelete(hSes, uid)) != 0)
{
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 1;
}
sapium.Logoff(hSes);
sapium.HandleRelease(hSes);
return 0;
}
static void Main(string[] args)
{
int rc;
for (int i = 0; i < 10; i++)
{
string uid = "Test" + i;
rc = AddUser(uid);
if (rc != 0) {
Console.WriteLine ("Error adding user: " + uid);
return;
}
rc = DelUser(uid);
if (rc != 0) {
Console.WriteLine ("Error deleting user: " + uid);
return;
}
Console.WriteLine("After handling user: " + uid);
}
Console.WriteLine("Press <Enter> to end");
Console.ReadKey();
}
}
}

Resources