Failure to call wip client create


#1

Guys

I loaded luasample into my Fastrack Supreme 20. Connected PPP OK. Print “Hello World” OK. :stuck_out_tongue:

Then I tried to connect GPRS but … :blush:

What is the problem? :blush: I thought maybe I didn’t activate a thread function or something, I l “events.lua”. Didn’t work. :mrgreen:

Thanks, guys.


#2

I’m pretty surprised by the absence of a wip.client_create().

  • Have you changed something in the sample’s config?
  • What does it print when you type “=wip”? (it should print the complete content of the wip module)
  • The bearer error “wrong state before start” is normal, you’re trying to start a bearer that was already started a couple of lines above.

#3

Hy,

I have the same problem.
I begin by “bearer_client” function which doesn’t return an error, but “wip.client_create” returns : “attempt to call field ‘client_create’ (a nil value)”.
When I type “=wip”, the “client_create” isn’t present, it print “tcp_server”, “tcp_client” and another WIP function but not this one.
I don’t think have changed anything…

Can you help me? What is the problem?

thanks


#4

OK that’s an out-of-date doc issue. wip.client_create() has been renamed wip.tcp_client(), as there are now wip.ftp_client(), wip.udp_client() etc.

The tutorial kept an incorrect reference to wip.client_create(), which had been copied in an example of the reference manual.
The reference part of the manual correctly referred to wip.tcp_client().

Both docs have been updated on the wiki.


#5

Thanks for your reply fft, It works fine now…


#6

I wrote this two simple function to connect to Bearer and disconnect from Bearer.
The first funcation is working fine to connect GPRS network but disconnect is not working.
It stack - I try to do manual what ‘close’ should do but the same.

please advice if i do it right

Thanks

gprs_config = { apn = 'my-apn' }
gprs_connect = nil


function Connect_GPRS()
	-- Connect to Bearer in GPRS
	print("Try to Connect to GPRS Bearer")
	gprs_connect = wip.bearer_client('GPRS', gprs_config)
	print ("Connect to GPRS Network (proc:", gprs_connect, "). APN=", gprs_config.apn)
	print("My Ip:", proc.bearers.GPRS.ip_addr)
end

function DisConnect_GPRS()
	-- DisConnect to Bearer in GPRS
	print("Try to DisConnect GPRS Bearer")
	gprs_connect:close()
	print ("DisConnected from GPRS Network")
end

#7

You do it fine, and your code works for me. There might be something unusual happening with your GPRS provider…

If you get stuck in bearer:close(), it means that your WIP bearer never sends the WIP_BEV_STOPPED event. I’d suggest that you:

  • Enable WIP traces, by adding “WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1” in your wip_netInitOpts() options.
  • Check what “[GPRS]: GPRS EVENT” traces you get when trying to disconnect: that way you’ll know what happens at GPRS level
  • Check the “[LUAW] SIGNAL” traces: that way you’ll know what’s actually reported to Lua.

#8

Thanks for the reply.

Can I send all LUA debug Message to USB port If Yes HOW?
(I am using Uart1 for LUA shell,UART2 to connect to PLC - serial device)

so i can not see the debug messgaes.
please see bellow debug message that I recive when I connect and disconnect from bearer - I disconnect PLC from Uart2 temporary.

If I am not mistaking this is the bearer close funcation in oatlua

function BEARER:close()
if debug.getfenv(self).state == “IP_CONNECTED” then
internal.bearer_stop(self)
wait(self,“STOPPED”)
end
internal.bearer_close(self)
end

And It Wait for STOPPED signal And I think I recived DISCONNECTED signal.

Is It right ?

Thanks

connection : gprs_connect = wip.bearer_client('GPRS', gprs_config)

[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca10c])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )

[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca00c])}
[LUAW] SIGNAL shell.line
[LUAW] Waking up: { [thread 0x180eb2bc] ([table 0x180ca28c])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )
[LUAW] RUN [thread 0x180e021c]
[LUAW] WAIT emitters = { shell }, events = { interrupt, background, eof, line, done } )
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
[LUAW] WAIT emitters = { GPRS }, events = { IP_CONNECTED, CONN_FAILED } )
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT ACTIVATE OK (cid=1): FCM open
[GPRS]: FCM subscribe: 3
[GPRS]: FCM EVENT FLOW OPENNED: -> CONNECTED
[LUAW] SIGNAL GPRS.IP_CONNECTED
[LUAW] Waking up: { [thread 0x180e021c] ([table 0x180ca0cc])}
[LUAW] SIGNAL [thread 0x180e021c].die
[LUAW] SIGNAL shell.done
[LUAW] Waking up: { [thread 0x180eb2bc] ([table 0x180ca32c])}
[LUAW] Waking up: { }
[LUAW] WAIT emitters = { shell }, events = { interrupt, background, eof, line, done } )



after :  gprs_connect:close()
-------------------------------------------

[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca08c])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )
[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca00c])}
[LUAW] SIGNAL shell.line
[LUAW] Waking up: { [thread 0x180eb2bc] ([table 0x180ca2cc])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )
[LUAW] RUN [thread 0x180e979c]
[LUAW] WAIT emitters = { shell }, events = { interrupt, background, eof, line, done } )
[GPRS]: stop: FCM close -> DISCONNECTING
[GPRS]: FCM unsubscribe (2)
[LUAW] WAIT emitters = { [userdata 0x180c67ec] }, events = { STOPPED } )
[GPRS]: FCM EVENT FLOW CLOSED: GPRS deactivate
[LUAW] SIGNAL at.CGEV
[GPRS]: GPRS EVENT: 2 (cid=1)
[GPRS]: GPRS EVENT DEACTIVATE OK/KO (cid=1): -> DISCONNECTED
[LUAW] SIGNAL GPRS.STOPPED

then I Press ctrl+C
and make again close : gprs_connect:close()
---------------------------------------------------------------------
[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca10c])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )
[LUAW] SIGNAL [channel TCPCLIENT 0x180e8b9c ready].read
[LUAW] Waking up: { [thread 0x180eba1c] ([table 0x180ca00c])}
[LUAW] SIGNAL shell.line
[LUAW] Waking up: { [thread 0x180eb2bc] ([table 0x180ca28c])}
[LUAW] WAIT emitters = { [channel TCPCLIENT 0x180e8b9c ready] }, events = { read, peer_close, error } )
[LUAW] RUN [thread 0x180e85dc]
[LUAW] WAIT emitters = { shell }, events = { interrupt, background, eof, line, done } )
[GPRS]: close: -> CLOSED
[LUAW] SIGNAL [thread 0x180e85dc].die
[LUAW] SIGNAL shell.done
[LUAW] Waking up: { [thread 0x180eb2bc] ([table 0x180cadac])}
[LUAW] Waking up: { }
[LUAW] WAIT emitters = { shell }, events = { interrupt, background, eof, line, done } )


after the second close the GPRS bearer is free.

thanks


#9

Oops, the code you’ve got for bearer:close() has a bug. It’s been fixed on the (newer) version I’m working on, but the wait line should read “wait(self.name, ‘STOPPED’)” instead of “wait(self, ‘STOPPED’)”.

Workaround: add the following somewhere in your code before the first time you use bearer:close():

function internal.bearers_methods:close()
   if debug.getfenv(self).state == "IP_CONNECTED" then 
      internal.bearer_stop(self)
      wait(self.name, "STOPPED")
   end
   internal.bearer_close(self)
end

This will let you work until the next version officially ships.


#10

About diverting traces to USB: yes you can, but it requires a bit of black magic to get windows to recognize the devkit’s USB port as an UART, and I’m not a specialist of Win32 intricacies…


#11

Thanks for your fast reply.
I will test the Workaround tomorrow .
about USB port is already recognize by windows in my notebook.
How I can configer the LUA shell to send debug messages to USB port.

thanks
I am going home now.


#12

If the USB port is recognized by windows , what further do we need to do in order to coonect to LUE via the USB?


#13

If the USB port is recognized as a serial port (not a modem!) by windows, then you can use it as a regular port, just substitute ‘USB’ as the uart name, where you would have used ‘UART1’ or ‘UART2’. You can use wip.fcm(‘USB’) to read/write data on it, or wip.bearer_client(‘USB’, your_config) to set up a TCP/IP link over PPP at up to 400Kbps, etc.